Android Question DB problem

Discussion in 'Android Questions' started by AbbasMohammed, Jul 5, 2015.

  1. AbbasMohammed

    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!!!
    Code:
    '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
     
  2. rboeck

    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?
     
    AbbasMohammed likes this.
  3. AbbasMohammed

    AbbasMohammed Member Licensed User

    what is defaultexternal and how can i correct it???
     
  4. klaus

    klaus Expert Licensed User

    Try to replace
    File.DirDefaultExternal
    by
    File.DirRootExternal
    or by
    File.DirInternal
     
    AbbasMohammed likes this.
  5. LucaMs

    LucaMs Expert Licensed User

    There are also errors:


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


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


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

    AbbasMohammed Member Licensed User

    still not working:(
     
  7. AbbasMohammed

    AbbasMohammed Member Licensed User

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

    Code:
    '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
     
  8. AbbasMohammed

    AbbasMohammed Member Licensed User

    i have also corrected the cursor Text error....but still not ok
     
  9. AbbasMohammed

    AbbasMohammed Member Licensed User

    with sqlite viewer i see only the table without the data in it!!!
     
  10. klaus

    klaus Expert Licensed User

    Post a small project, as a zip file, showing the problem.
     
    AbbasMohammed likes this.
  11. LucaMs

    LucaMs Expert Licensed User

    Try this.
     

    Attached Files:

    AbbasMohammed likes this.
  12. AbbasMohammed

    AbbasMohammed Member Licensed User

    Dear LucaMs, thank you very much, your solution is working 100%.:)
     
    LucaMs likes this.
  13. AbbasMohammed

    AbbasMohammed Member Licensed User

    also i would like to direct a big thankfull to all how tried to help me....many thanks to all
     
    LucaMs likes this.
Loading...