OK so I am trying to set up a database and this is what i have so far
**********************
The four lines are all uncommented but the first two ae my first try and second two are my second try and i commented out the non working ones when trying other things they are just here to show how i was doing it. Also all of the variables are already in globals and working fine. I just didn't see the need to copy that code.
**********************
But when I try to call populatedatabase it skips over everything.
this line works:
sql1.ExecNonQuery("INSERT INTO table1 VALUES ('TED', 22, 41, 21, 01, 11, 61, 01, 01, 11, 'george', 8)")
but this doesnt:
sql1.ExecNonQuery("INSERT INTO table1 VALUES ('george', "+EBmakep1+", 4, 2, 0, 1, 6, 0, 0, 1, 'george', 8)")
So obviously it has something to do with the "+variable+" format
I have tried to find another way to pass it but i havent found a way.
In the tutorial it says use execnonquery2 to put ? in place of values but doesn't have anything on how to do it to write known values
All I'm trying to do is write the values i have stored in the variables to a database. Any help would be appreciated. And thank you in advance.
B4X:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim sql1 As SQL
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
If FirstTime Then
sql1.Initialize(File.DirDefaultExternal, DateTime.GetMonth(DateTime.Now) &"."& DateTime.GetDayOfMonth(DateTime.Now) &"."& DateTime.GetYear(DateTime.Now) & " " & DateTime.TIME(DateTime.Now) & ".db", True)
End If
createtables
End Sub
Sub populatedatabased
sql1.BeginTransaction
Try
sql1.ExecNonQuery("INSERT INTO table1 VALUES ('"+playeronename+"', "+EBmakep1+", "+EBMissp1+", "+EBdefp1+", "+EBLotp1+", "+EBMobP1+", "+EBDeadp1+", "+EBe8P1+", "+EB8obp1+", "+EBbnrp1+", '"+winnerwinner+"', "+gamechosen+")")
sql1.ExecNonQuery("INSERT INTO table1 VALUES ("+playertwoname+", "+EBmakep2+", "+EBMissp2+", "+EBdefp2+", "+EBLotp2+", "+EBMobP2+", "+EBDeadp2+", "+EBe8P2+", "+EB8obp2+", "+EBbnrp2+", "+winnerwinner+", "+gamechosen+")")
sql1.ExecNonQuery("INSERT INTO table1 VALUES ('george', "+EBmakep1+", 4, 2, 0, 1, 6, 0, 0, 1, 'george', 8)")
sql1.ExecNonQuery("INSERT INTO table1 VALUES ('TED', 22, 41, 21, 01, 11, 61, 01, 01, 11, 'george', 8)")
sql1.TransactionSuccessful
Catch
Log(LastException.Message)
End Try
sql1.EndTransaction
End Sub
Sub createtables
sql1.ExecNonQuery("DROP TABLE IF EXISTS table1")
sql1.ExecNonQuery("CREATE TABLE table1 (Col1 TEXT, col2 INTEGER, col3 INTEGER, col4 INTEGER, col5 INTEGER, col6 INTEGER, col7 INTEGER, col8 INTEGER, col9 INTEGER, col10 INTEGER, col11 TEXT, col12 INTEGER)")
End Sub
**********************
The four lines are all uncommented but the first two ae my first try and second two are my second try and i commented out the non working ones when trying other things they are just here to show how i was doing it. Also all of the variables are already in globals and working fine. I just didn't see the need to copy that code.
**********************
But when I try to call populatedatabase it skips over everything.
this line works:
sql1.ExecNonQuery("INSERT INTO table1 VALUES ('TED', 22, 41, 21, 01, 11, 61, 01, 01, 11, 'george', 8)")
but this doesnt:
sql1.ExecNonQuery("INSERT INTO table1 VALUES ('george', "+EBmakep1+", 4, 2, 0, 1, 6, 0, 0, 1, 'george', 8)")
So obviously it has something to do with the "+variable+" format
I have tried to find another way to pass it but i havent found a way.
In the tutorial it says use execnonquery2 to put ? in place of values but doesn't have anything on how to do it to write known values
All I'm trying to do is write the values i have stored in the variables to a database. Any help would be appreciated. And thank you in advance.
Last edited: