Android Question Why can not we see the changes in DB ,eventough we make a change via using Emulator?

Itila Tumer

Active Member
Licensed User
Longtime User
I have normal persons.db ,
I compile the program and INSERT/DELETE data on db. anything.

But after I close emulator and check the persons.db again ,I cannot see any changes in it. What can be the reason?

I use SQLiteLight2 example:


If FirstTime Then
File.Delete(File.DirInternal, "persons.db") ' only for testing, removes the database
If File.Exists(File.DirInternal, "persons.db") = False Then
File.Copy(File.DirAssets, "persons.db", File.DirInternal, "persons.db"
SQL1.Initialize(File.DirInternal, "persons.db", True)
File.Copy(File.DirAssets, "persons.db", File.DirInternal, "persons.db")
Else
SQL1.Initialize(File.DirInternal, "persons.db", True)
End If
End If
 

Itila Tumer

Active Member
Licensed User
Longtime User
Ok , I tried but , Just cant see though

I think the problem is from INSERT INTO .
If I add the data ,another layout opens. It says new ID is added, but after I return Main menu (at SQLite Light2)
I cannot see new added data, AND if want to add new data again, it contunie from last new ID , and it seems goes normal from last ID. But whenever I go to main layout I cannot see . sorry about my english. I hope I could intreduce myself what I mean.

Do I rith code for persons.db TWO TABLES which is persons and body




[Sub AddEntry]
[Dim Query As String]
[Dim Cursor1 As Cursor]
[Dim ID As Int]
[Query = "SELECT * FROM persons WHERE FirstName = ? AND LastName = ? AND Sex= ? AND BirthDay = ? AND BirthCity = ? AND FatherName = ?" ]
[Cursor1 = Activity2.SQL1.ExecQuery2(Query, Array As String (edtFirstName.Text,edtLastName.Text,edtSex.Text,edtBirthDay.Text,edtBirthCity.Text,edtFatherName.Text))]

[If Cursor1.RowCount > 0 Then]

[ToastMessageShow("This entry already exists", False)]
[Else]

[Query = "INSERT INTO persons VALUES (NULL, ?, ?, ?, ?, ?, ?, ?)"]
[Activity2.SQL1.ExecNonQuery2(Query, Array As String(edtFirstName.Text,edtLastName.Text,edtSex.Text,edtBirthDay.Text,edtBirthCity.Tex,edtFatherName.Text))]

[ToastMessageShow("Entry added", False)]
[ID = Activity2.SQL1.ExecQuerySingleResult("SELECT max(ID) FROM persons ")][Activity2.RowNumber = Activity2.RowNumber + 1]
[Activity2.IDList.Add(ID)]
[Activity2.CurrentIndex = Activity2.IDList.Size - 1]
[edtID.Text = ID]
[End If]
[Cursor1.Close]

[ShowButtons]
[/End Sub ]
 

Attachments

  • Database.zip
    42.4 KB · Views: 166
Last edited:
Upvote 0

mangojack

Expert
Licensed User
Longtime User
Itila .. I see you tried to use Code Tags . Maybe you are confused.

You can insert code manually by typing the Tags or use the buttons in the bar above your post .. see images.
 

Attachments

  • Manual Code Tags.JPG
    20.6 KB · Views: 159
  • Auto Code Tags.JPG
    11.5 KB · Views: 165
Upvote 0

Itila Tumer

Active Member
Licensed User
Longtime User
I think I handle my problem. I used that . I learned two table should be used individually.
I have two table which are persons and body.

B4X:
Query = "INSERT INTO persons  VALUES (NULL, ?, ?, ?, ?)"
    Main.SQL1.ExecNonQuery2(Query, Array As String(edtFirstName.Text, edtLastName.Text, edtCity.Text, edtBoy.Text))
    Query = "INSERT INTO body  VALUES (NULL, ?)" 
    Main.SQL1.ExecNonQuery2(Query, Array As String(edtBoy.Text))
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…