Android Question DB problem

AbbasMohammed

Member
Licensed User
Hi , Iam trying to make simple dictionary for my germany lectures, but the problem is that, inspite of inserting data to the table in the DB , its not added and the cursor1.rowcount is always 0!!!
B4X:
'Activity module
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
   
    Dim cursor1 As Cursor
    Dim Pid As Int
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim EditText1 As EditText
    Dim Button1 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    SQL1.Initialize(File.DirDefaultExternal, "Germany.db", True)
    CreateTable
    InsertManyRows
'    Activity.LoadLayout ("CreatDbLayout")
'    If File.Exists(File.DirInternal, "Germany.db")=False Then
'    SQL1.Initialize(File.DirInternal, "Germany.db", True)
''    CreateTable
'    InsertManyRows
'    Else
'    SQL1.Initialize(File.DirInternal, "Germany.db", True)
'    End If
    cursor1=SQL1.ExecQuery("SELECT WordId ,GermanyWord ,ArabicWord TEXT,LecNo  FROM table1")
    Msgbox(cursor1.RowCount,"")
    Activity.LoadLayout ("CreatDbLayout")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub CreateTable
SQL1.ExecNonQuery ("DROP TABLE IF EXISTS table1")
SQL1.ExecNonQuery("CREATE TABLE table1(WordId INTEGER,GermanyWord TEXT,ArabicWord TEXT,LecNo INTEGER)")
End Sub


Sub Button1_Click
Pid=EditText1.Text
cursor1.Position =Pid
Msgbox(cursor1.GetString("GermanyWord"),cursor1.GetInt("WordId"))
End Sub
Sub InsertManyRows
SQL1.BeginTransaction
Try
'21-6-2015
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SQL1.ExecNonQuery("INSERT INTO table1 VALUES('0','der  Advent','مجيء','7')")
SQL1.ExecNonQuery("INSERT INTO table1 VALUES('1','der  Adventskranz','إكليل قدوم','7')")
SQL1.ExecNonQuery("INSERT INTO table1 VALUES('2','der  Anlass','بمناسبة','7')")
SQL1.ExecNonQuery("INSERT INTO table1 VALUES('3','der  April','أبريل','7')")
SQL1.ExecNonQuery("INSERT INTO table1 VALUES('4','die  Atmosphäre','الجو','7')")
SQL1.ExecNonQuery("INSERT INTO table1 VALUES('5','die  Aufregung','الإثارة','7')")
SQL1.ExecNonQuery("INSERT INTO table1 VALUES('6','der  Backofen','الفرن','7')")
SQL1.ExecNonQuery("INSERT INTO table1 VALUES('7','die  Bäuerin','زوجة المزارع','7')")
SQL1.ExecNonQuery("INSERT INTO table1 VALUES('8','der  Bikini','بيكيني','7')")
SQL1.ExecNonQuery("INSERT INTO table1 VALUES('9','der  Blumenstrauß','باقة','7')")
SQL1.ExecNonQuery("INSERT INTO table1 VALUES('10','die  Bluse','بلوزة','7')")

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SQL1.TransactionSuccessful
Catch
End Try
SQL1.EndTransaction
Msgbox("O.K","")
End Sub
 

rboeck

Well-Known Member
Licensed User
Hi, i copied your example and without any changes i got 11 as Rowcount. Maybe you have a problem with defaultexternal?
 

LucaMs

Expert
Licensed User
There are also errors:


B4X:
SQL1.ExecNonQuery("CREATE TABLE table1(WordId INTEGER, GermanyWord TEXT, ArabicWord TEXT, LecNo INTEGER)")
It's ok.


B4X:
cursor1 = SQL1.ExecQuery("SELECT WordId , GermanyWord, ArabicWord TEXT, LecNo  FROM table1")
It's not ok, TEXT


B4X:
SQL1.ExecNonQuery("INSERT INTO table1 VALUES('0', 'der  Advent', 'مجيء' ,'7')")
It's not ok; 7, without apostrophes, should be the last value.
 

AbbasMohammed

Member
Licensed User
i deleted the column that contains 7 , but still not working

B4X:
'Activity module
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
  
    Dim cursor1 As Cursor
    Dim Pid As Int
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim EditText1 As EditText
    Dim Button1 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
'    File.MakeDir(File.DirRootExternal,"Germany")
    SQL1.Initialize (File.DirDefaultExternal, "Germany.db", True)
'    SQL1.Initialize(File.DirInternal, "Germany.db", True)
    CreateTable
    InsertManyRows
'    Activity.LoadLayout ("CreatDbLayout")
'    If File.Exists(File.DirInternal, "Germany.db")=False Then
'    SQL1.Initialize(File.DirInternal, "Germany.db", True)
''    CreateTable
'    InsertManyRows
'    Else
'    SQL1.Initialize(File.DirInternal, "Germany.db", True)
'    End If
    cursor1=SQL1.ExecQuery("SELECT WordId ,GermanyWord ,ArabicWord  FROM table1")
    Msgbox(cursor1.RowCount,"")
    Activity.LoadLayout ("CreatDbLayout")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub CreateTable
SQL1.ExecNonQuery ("DROP TABLE IF EXISTS table1")
SQL1.ExecNonQuery("CREATE TABLE table1(WordId INTEGER,GermanyWord TEXT,ArabicWord TEXT)")
End Sub


Sub Button1_Click
Pid=EditText1.Text
cursor1.Position =Pid
Msgbox(cursor1.GetString("GermanyWord"),cursor1.GetInt("WordId"))
End Sub
Sub InsertManyRows
SQL1.BeginTransaction
Try
'21-6-2015
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  SQL1.ExecNonQuery("INSERT INTO table1 VALUES('0','der  Advent','مجيء')")
SQL1.ExecNonQuery("INSERT INTO table1 VALUES('1','der  Adventskranz','إكليل قدوم')")
SQL1.ExecNonQuery("INSERT INTO table1 VALUES('2','der  Anlass','بمناسبة')")
SQL1.ExecNonQuery("INSERT INTO table1 VALUES('3','der  April','أبريل')")
SQL1.ExecNonQuery("INSERT INTO table1 VALUES('4','die  Atmosphäre','الجو')")
SQL1.ExecNonQuery("INSERT INTO table1 VALUES('5','die  Aufregung','الإثارة')")
SQL1.ExecNonQuery("INSERT INTO table1 VALUES('6','der  Backofen','الفرن')")
SQL1.ExecNonQuery("INSERT INTO table1 VALUES('7','die  Bäuerin','زوجة المزارع')")
SQL1.ExecNonQuery("INSERT INTO table1 VALUES('8','der  Bikini','بيكيني')")
SQL1.ExecNonQuery("INSERT INTO table1 VALUES('9','der  Blumenstrauß','باقة')")
SQL1.ExecNonQuery("INSERT INTO table1 VALUES('10','die  Bluse','بلوزة')")
SQL1.ExecNonQuery("INSERT INTO table1 VALUES('11','die  Bratwurst','السجق')")

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SQL1.TransactionSuccessful
Catch
End Try
SQL1.EndTransaction
Msgbox("O.K","")
End Sub
 
Top