Android Question Determine variable is an uninitialized ResultSet?

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Is this possible?
Tried lots of approaches, but not succeeded yet.
Best I can determine is to it is an uninitialized object.

RBS
 

LucaMs

Expert
Licensed User
Longtime User
Based on you wrote in the post, it seems you got exactly what you wrote in the title :oops:

However, even though I haven't tried it yet, I think the ResultSet is always initialized (you have to use the ExecQuery versions, not the ExecNONQuery versions, of course) and that at most it will be empty, so the classic example:
B4X:
Dim Cursor As ResultSet
Cursor = SQL1.ExecQuery("SELECT col1, col2 FROM table1")
Do While Cursor.NextRow
    Log(Cursor.GetString("col1"))
    Log(Cursor.GetInt("col2"))
Loop
the loop will not execute even once.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
resultset requires using a resultset.nextrow loop as explained above (and previously the last time you raised the same topic.)

if you're using b4a, you can still use cursor. if you use cursor, then you can query cursor.rowcount. if rowcount = 0, there were no hits. resultset is an extension of cursor and is valid across b4x platforms. cursor works for b4a.
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Based on you wrote in the post, it seems you got exactly what you wrote in the title :oops:

However, even though I haven't tried it yet, I think the ResultSet is always initialized (you have to use the ExecQuery versions, not the ExecNONQuery versions, of course) and that at most it will be empty, so the classic example:
B4X:
Dim Cursor As ResultSet
Cursor = SQL1.ExecQuery("SELECT col1, col2 FROM table1")
Do While Cursor.NextRow
    Log(Cursor.GetString("col1"))
    Log(Cursor.GetInt("col2"))
Loop
the loop will not execute even once.
>> the loop will not execute even once.

I can see you haven't tried, try this:

B4X:
    Dim Cursor As ResultSet
    Cursor = SQL1.ExecQuery("SELECT 1")
    Do While Cursor.NextRow
        Log(Cursor.GetString2(0))
    Loop

The log will show: 1

Let me try explain my question better:
Say we do:

B4X:
Dim RS As ResultSet
Log(DetermineVarType(RS))

Then what should the code in DetermineVarType be to tell me that RS is an uninitialized ResultSet?

RBS
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
The log will show: 1
And? It is correct (I think, not tried); I don't understand that part.

Then what should the code in DetermineVarType be to tell me that RS is an uninitialized ResultSet?
I don't know in what strange cases you should be able to determine if a ResultSet is initialized; however, the IsInitialized property exists, as in every object.
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
And? It is correct (I think, not tried); I don't understand that part.


I don't know in what strange cases you should be able to determine if a ResultSet is initialized; however, the IsInitialized property exists, as in every object.
>> however, the IsInitialized property exists, as in every object

Not if that object is passed as type Object.
So, in my example DetermineVarType will be something like this:

B4X:
Sub DetermineVarType(oObject As Object) As String
'code
End Sub

RBS
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
>> however, the IsInitialized property exists, as in every object

Not if that object is passed as type Object.
So, in my example DetermineVarType will be something like this:

B4X:
Sub DetermineVarType(oObject As Object) As String
'code
End Sub

RBS
1669429370778.png
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Since you can't pass an uninitialized object to that function, you should first verify that it is.

However, in extreme cases, like perhaps this could be, it is customary to use a Try-Catch block.
>> use a Try-Catch block

Have tried that, but couldn't make it work.
So, it seems the best I can do is determine if it is an uninitialized object and only if it isn't determine the type.

RBS
 
Upvote 0
Top