sql from second activity

buras3

Active Member
Licensed User
Longtime User
hello

i have a problem
i defined sql in main activity
in the activity create i am making the tables
every thing works fine

but when i am trying to call a query from second activity
i get an error that i can't query because there is no tables yet

how can i resolve this?
i tried with module but it's the same

tanks
 

buras3

Active Member
Licensed User
Longtime User
i did that

tank you for replay

i did that
i declared the sql in the main activity - global prosses
my question is :
when i am compiling it seems that all the activity's run together
not like vb form
i want to do this:
the main activity declare sql and build tables
the second activity needs to make a query to a list
but i get error
 
Upvote 0

dealsmonkey

Active Member
Licensed User
Longtime User
tank you for replay

i did that
i declared the sql in the main activity - global prosses
my question is :
when i am compiling it seems that all the activity's run together
not like vb form
i want to do this:
the main activity declare sql and build tables
the second activity needs to make a query to a list
but i get error

What error are you getting. I have done this is an app without an issue. I create the tables on the main screen then query on another. if you look at the app I posted in the share your creations' thread, you will see it done there.

Neil
 
Upvote 0

buras3

Active Member
Licensed User
Longtime User
Code

my error is:
Error description: Undeclared variable 'sql1' is used before it was assigned any value.

the code
main activity:
Sub Process_Globals
Dim sql1 As SQL
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
SQL1.Initialize(File.DirDefaultExternal, "Calls.db", True)
End If
Activity.LoadLayout("Main")
CreateTable
FillTables
end sub

******so far working********

second activity:

Sub Activity_Create(FirstTime As Boolean)

'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Activity.LoadLayout("calls")
listview1.Visible=False
Dim Cursor1 As Cursor
Cursor1 = SQL1.ExecQuery("SELECT Name FROM Calllog")
For i = 0 To Cursor1.RowCount - 1
Cursor1.Position = i
ListView1.AddSingleLine(" " & Cursor1.GetString("Name") )
Next
Cursor1.Close
End Sub

tank you all
 
Upvote 0

dealsmonkey

Active Member
Licensed User
Longtime User
my error is:
Error description: Undeclared variable 'sql1' is used before it was assigned any value.

the code
main activity:
Sub Process_Globals
Dim sql1 As SQL
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
SQL1.Initialize(File.DirDefaultExternal, "Calls.db", True)
End If
Activity.LoadLayout("Main")
CreateTable
FillTables
end sub

******so far working********

second activity:

Sub Activity_Create(FirstTime As Boolean)

'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Activity.LoadLayout("calls")
listview1.Visible=False
Dim Cursor1 As Cursor
Cursor1 = SQL1.ExecQuery("SELECT Name FROM Calllog")
For i = 0 To Cursor1.RowCount - 1
Cursor1.Position = i
ListView1.AddSingleLine(" " & Cursor1.GetString("Name") )
Next
Cursor1.Close
End Sub

tank you all

in the 2nd activity, you must reference the SQL as main.SQL1 ie :

B4X:
Activity.LoadLayout("calls")
listview1.Visible=False 
Dim Cursor1 As Cursor
Cursor1 = main.SQL1.ExecQuery("SELECT Name FROM Calllog")
For i = 0 To Cursor1.RowCount - 1
   Cursor1.Position = i
   ListView1.AddSingleLine("  " & Cursor1.GetString("Name") )
Next
Cursor1.Close
End Sub

Hope this helps

Neil
 
Upvote 0

eps

Expert
Licensed User
Longtime User
ahem.....

Dim sql1 As SQL

should this not be

Dim SQL1 As SQL

Although this may not be the probelm?

Am I being thick? You seem to have two events "Sub Activity_Create(FirstTime As Boolean)" how does this work?

This is a compile error your getting isn't it? You're not getting to code execution are you?

I think, for some reason, the Dim of SQL1 isn't getting recognised by the compiler.. Try deleting that line and re-entering it..

If I comment out the Dim of SQL1, I get the following :

Compiling code. Error
Error parsing program.
Error description: Undeclared variable 'sql1' is used before it was assigned any value.
Occurred on line: 38
If SQL1.IsInitialized = False Then

Is the dim of SQL1 recognised? If it is, is it right at the top, i.e. in the sub process_globals on line1?
 
Last edited:
Upvote 0
Top