Team Developer 2005.1 - Into Variable Always Empty - guptateamdeveloper

We are handling a legacy code which based on Team Developer 2005.1
There is a query like
!!CB!! 70
Set sSqlCommand = '
SELECT name, value
INTO :sName, :sValue
FROM av_system_settings
WHERE name LIKE \'Company_\%\''
If NOT SqlPrepareAndExecute( hSqlMain, sSqlCommand )
Return FALSE
Loop
If SqlFetchNext( hSqlMain, nFetch )
...
Here the into variable :sName, :sValue are Strings but it always have empty value although the record has been looped correctly through SqlFetchNext
The into variable on other place are all fine. Just not working here one place.
Have run out of brain on this... Any idea? Guys :)

For testing, you can use SqlImmediate(sSqlCommand ) instead of sqlprepareandexecute( ). If sName and sValue have value after
executing sqlImmediate means sql working fine.
Make sure SqlConnect() function returns true value. If it returns false then make sure database creditionals are correct.
If the sValue variable need to hold Long data then please have a look on SqlSetLongBindDatatype ( ) function.
Check the value of sql handle hsqlMain, if it have a postive value or one it means that handle connected properly. Otherwise
if the handle value is null or zero, it means handle not connected.
Try to use SqlFetchRow ( hsqlMain, nRow, nFetch ) and increment the value of nRow by 1 till function return false or the value of nFetch becomes FETCH_EOF.
Set nRow = 0
While (TRUE)
If not SqlFetchRow( hsqlMain, nRow, nFetch )
Break
Set nRow = nRow + 1

Check nFetch after SqlFetchNext to be sure a record was found.
If nFetch = FETCH_Ok , a record was found.
So try calling SqlVarSetup(hSqlMain) before the SqlFetchNext , so the into vars have context.
Also try qualifying the into vars e.g. :hWndForm.frmTest.sName .
If nFetch = FETCH_EOF , no record was found .

Related

My number value isn't updating, how do I fix it?

So I was trying to make it so that every second the loop changed the value of the number value but it keeps returning either nil or 0. I tried adding it as a local value that affected the actual value and a few other things like making it a string instead and replacing the string with a new one but that still didn't return anything. This is my code now and it's the code that returns 0 and not nil or an error.
local SecondsAfterGameStart = game.ServerStorage.SecondsAfterGameStart.Value
while true do
wait(0.1)
SecondsAfterGameStart = SecondsAfterGameStart + 1
end
When you save SecondsAfterGameStart.Value into a local variable, you are not keeping a reference to the original NumberValue object, you are copying its value into the local variable. Later in your while loop, you are accessing and modifying a variable and not the original object, so changes are never saved back to the object in the ServerStorage.
So, instead of saving the Value, hold onto the entire NumberValue itself. Then you can update the Value directly.
local SecondsAfterGameStart = game.ServerStorage.SecondsAfterGameStart
while true do
wait(0.1)
SecondsAfterGameStart.Value = SecondsAfterGameStart.Value + 1
end

Cant use user defined function return value in where clause

I have a UDF in Esper which returns an int
getVal(int val){
//doing stuff
return val;
}
if i do this
select getVal(eventAttribute) from Event
it returns
{getVal(eventAttribute)=3 } //3 example could be anything
However if i specify
select getVal(eventAttribute) from Event WHERE getVal(eventAttribute) = 3
the listener wont update
Does anyone know why? Do I have to set the attribute in the Event class? since it updates from the select clause but with a WHERE clause even though it returns an int = 3
EDIT:
insert into Stream select getVal(attribute) as value
select value from Stream where value > 3
This works.
Are you sure that "getVal" always returns the same value for a given "eventAttribute" and "eventAttribute" is immutable? If yes provide some test code to reproduce?

gmod GameMode Lua. IsPlayer retuning nill value

I'm trying to make a gmod gamemode. In my init.lua I wanted it so that way team members can't hurt each other. So I used this code
function GM:EntityTakeDamage( target, dmginfo )
if ( target:IsPlayer() and dmginfo:IsPlayer() ) then
if (dmginfo:Team() == target:Team()) then
dmginfo:ScaleDamage( 0.0 ) // Sets damage to 0
end
end
end
However it's giving me the error telling me that IsPlayer() is a nil value even though it should be returning a boolean. It points to no other lines other then the line with IsPlayer() and it's saying it is IsPlayer()
you have a typo in line 3. dminfo
You should narrow down which of your multiple IsPlayer() calls actually is nil
dmgInfo is a CTakeDamageInfo which has no function IsPlayer()
single line Lua comments are opened with --, not //
https://wiki.garrysmod.com/page/Category:CTakeDamageInfo
If you call a function and it says its nil, then check if it even exists. Or even better, check this befor you use the function in the first place.
And to prevent you from coming back in a minute, CTtakeDamageInfo also does not have a function Team() as well.
Check out CTDamageInfo:GetAttacker()

What happens if I call ParamByName for a parameter that doesn't exist?

I'm very new to Delphi and received the following piece of code (left out some irrelevant parts) for which I'm trying to understand what it does:
object SelectCosts: TIBQuery
SQL.Strings = (
'SELECT * FROM costs '
'WHERE code = :code')
ParamData = <
item
DataType = ftUnknown
Name = 'code'
ParamType = ptUnknown
end>
end
In another file, that query is used, but a parameter that is not defined in the query is added.
DM_HRV.SelectCosts.ParamByName('part').Value := 1;
Does this parameter 'part' change anything about the selection made? In other words: is the SQL query automatically changed into the following?
'SELECT * FROM costs '
'WHERE code = :code'
'AND part = :part'
That means that the SQL statement might be changed at run-time. so when that query is used the SQL already contains AND part = :part.
If the SQL statement does not contain this extra parameter part, an Exception will be raised when assigning ParamByName('part').Value := 1.
I'm assuming you didn't confuse SelectCosts reference (which is in DM_HRV and not other DM).
The following statement in your post does not add a parameter, it sets its value:
DM_HRV.SelectCosts.ParamByName('part').Value := 1;
To add a parameter at runtime, use CreateParam as follows:
if DM_HRV.SelectCosts.Params.FindParam('Part') = nil then
DM_HRV.SelectCosts.Params.createParam(ftString, 'Part', ptInput);
The query doesn't get modified automatically, you have to do that yourself.
In your first snip, the ParamType and InputType are not defined, you can change that in the IDE by access the parameter list (Params) property editor, and updating those values.
Adding a new parameter does not change the query. You have to do that yourself.

How to retrieve a value from a recordset that is not a return value or output parameter using vb6

I have a stored proc on an existing 3rd party application (SQL 2005) that I wish to interact with.
It is an insert statement followed by a select statement as follows;
Set #CustomerId = Cast(SCOPE_IDENTITY() As [int])
Select #CustomerId
Using VB6 how do I access the value of #CustomerID?
set rs = cmd.Execute
is not returning a resultset as expected...
[Edit]
rs.Fields.Count is 0.
Any attempt to access the resulting recordset, like rs(0).Value simply causes an "Item not found..." error.
I would guess that your stored procedure is returning more than one recordset.
If this is the case, you can use the NextRecordset() method to iterate through them.
MSDN:
If a row-returning command executes successfully but returns no records,
the returned Recordset object will be
open but empty. Test for this case by
verifying that the BOF and EOF
properties are both True.
If a non–row-returning command executes successfully, the returned
Recordset object will be closed, which
you can verify by testing the State
property on the Recordset.
When there are no more results, recordset will be set to Nothing.
This means I would suggest something like this to solve your problem:
Set rs = cmd.Execute
''# fetch the first value of the last recordset
Do Until rs Is Nothing
If rs.State = adStateOpen Then
If Not (rs.BOF And rs.EOF) Then
''# You can do a different sanity check here, or none at all
If rs.Fields(0).Type = adInteger Then
CustomerId = rs.Fields(0).Value
End If
End If
End If
Set rs = rs.NextRecordSet
Loop
MsgBox CustomerId

Resources