Hello everybody.
My main problem right now is that my app crash when the app read that line with the Select:
Before that I do a test to know if there is a DB and if not create it:
Here the code to create the table after that:
This happen in the first activity.
In the second I try to add a record like that:
I test all that in a tablet (Huawei Mediapad M1 with an 8" screen 1280x800 pixels) with Android 4.2.2 without root and without (external) sdcard.
What am I missing ?
I'm stucked right now. Any help apreciated.
Thank you...
Lou
My main problem right now is that my app crash when the app read that line with the Select:
B4X:
Sub ContarEncuestas
Dim SQLResult As Object
SQLResult = SQL1.ExecQuerySingleResult("SELECT COUNT(*) FROM viajeros WHERE ca_enviado = 'N'")
Log(SQLResult)
If SQLResult = Null Then 'si hay encuestas sin enviar
LblNumEnc.Text = "0" 'set the row count variable
Else
LblNumEnc.Text = SQLResult
End If
End Sub
B4X:
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
If FirstTime Then
' File.Delete(File.DirInternal, "latbus.db") ' only for testing, removes the database
'check if the database already exists
If File.Exists(File.DirInternal, "latbus.db") = False Then
'if not, initialize it
SQL1.Initialize(File.DirInternal, "latbus.db", True)
'and create it
CreateDataBase
End If
End If
Activity.LoadLayout("MenuPrincipal")
'scvTest.Panel.LoadLayout("MenuPrincipal")
ContarEncuestas
End Sub
B4X:
Sub CreateDataBase
Dim Query As String
Query = "CREATE TABLE viajeros (ca_id TEXT Not Null UNIQUE, ca_empresa TEXT Not Null, ca_ntrabaj TEXT Not Null, "
Query = Query & "ca_fecha TEXT Not Null, ca_hora TEXT Not Null, ca_sexo TEXT Not Null, ca_edad TEXT Not Null, "
Query = Query & "ca_perfil TEXT Not Null, ca_postal TEXT Not Null, ca_nacionalidad TEXT Not Null, "
Query = Query & "ca_veces TEXT Not Null, ca_tipousu TEXT Not Null, ca_linea TEXT Not Null, ca_usobus TEXT Not Null, "
Query = Query & "ca_bus TEXT, ca_liencu TEXT, ca_puntimp TEXT Not Null, ca_punserv TEXT Not Null, "
Query = Query & "ca_frecimp TEXT Not Null, ca_frecsuf TEXT Not Null, ca_buscon TEXT Not Null, ca_busade TEXT Not Null, "
Query = Query & "ca_conpre TEXT Not Null, ca_conade TEXT Not Null, ca_infemp TEXT Not Null, ca_infade TEXT Not Null, "
Query = Query & "ca_valglo TEXT Not Null, ca_enviado TEXT Not Null, PRIMARY KEY(ca_id));"
SQL1.ExecNonQuery(Query)
End Sub
This happen in the first activity.
In the second I try to add a record like that:
B4X:
Sub AddEntry
Dim Query As String
'add the entry
'a NULL for the ID column increments the primary key automatically by one
'we use ExecNonQuery2 because it's easier, we don't need to take care of the data types
Query = "INSERT INTO viajeros VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
SQL1.ExecNonQuery2(Query, Array As String(ID_BD_Viajeros, dbEmpInspector, dbCodigoInspector, Fecha, Hora, Sexo, Edad, Perfil, dbCPostal, dbNacionalidad, edtFreqUso.Text, BonoBillete, dbLineaHabitual, Motivo, edtCodigoBus.Text, edtCodigoLinea.Text, ImportPuntual, ServicioPuntual, ImportFrec, FrecSufi, CondiAuto, AutoAdec, ComportCond, CondAten, ValorInform, InformAdec, ValGlobal, Enviado))
Log(SQL1)
Msgbox("Encuesta grabada", "Enhorabuena") ' confirmation for the user
StartActivity("Main")
End Sub
I test all that in a tablet (Huawei Mediapad M1 with an 8" screen 1280x800 pixels) with Android 4.2.2 without root and without (external) sdcard.
What am I missing ?
I'm stucked right now. Any help apreciated.
Thank you...
Lou