B4J Question DBUtils: Broken?

LWGShane

Well-Known Member
Licensed User
Longtime User
B4X:
TheSQL.InitializeSQLite(File.DirApp, "db.db", True)

  
Dim Fields As Map
Fields.Initialize
Fields.Put("Name", "TEXT")

Dim ListOfMaps As List
ListOfMaps.Initialize
Dim M As Map
M.Initialize
M.Put("Name", "Olimar")
M.Put("Name", "Louie")
M.Put("Name", "Alph")
ListOfMaps.Add(M)
        
DBUtils.CreateTable(TheSQL, "Name", Fields , "Key")
DBUtils.InsertMaps(TheSQL, "Name", ListOfMaps)
DBUtils.ExecuteTableView(TheSQL, "SELECT Name FROM Name", Null, 1, TableView1)

Code doesn't insert all three keys. Already tried a "For" statement. Doesn't work. TableView1 only displays Alph.
 

Eumel

Active Member
Licensed User
Longtime User
You overwrite the key "Name" always, so only the last record will insert.

B4X:
Dim M As Map
M.Initialize
M.Put("Name", "Olimar")
ListOfMaps.Add(M)
Dim M As Map
M.Initialize
M.Put("Name", "Louie")
ListOfMaps.Add(M)
Dim M As Map
M.Initialize
M.Put("Name", "Alph")
ListOfMaps.Add(M)
 
Upvote 0

LWGShane

Well-Known Member
Licensed User
Longtime User
You overwrite the key "Name" always, so only the last record will insert.

B4X:
Dim M As Map
M.Initialize
M.Put("Name", "Olimar")
ListOfMaps.Add(M)
Dim M As Map
M.Initialize
M.Put("Name", "Louie")
ListOfMaps.Add(M)
Dim M As Map
M.Initialize
M.Put("Name", "Alph")
ListOfMaps.Add(M)

Tried it, and it still displays the last record.

Code:

B4X:
Dim Fields As Map
Fields.Initialize
Fields.Put("Name", "TEXT")

Dim ListOfMaps As List
ListOfMaps.Initialize
Dim M As Map
M.Initialize
M.Put("Name", "Olimar")
ListOfMaps.Add(M)
Dim M As Map
M.Initialize
M.Put("Name", "Louie")
ListOfMaps.Add(M)
Dim M As Map
M.Initialize
M.Put("Name", "Alph")
ListOfMaps.Add(M)


DBUtils.CreateTable(TheSQL, "Name", Fields , "Key")
DBUtils.InsertMaps(TheSQL, "Name", ListOfMaps)
DBUtils.ExecuteTableView(TheSQL, "SELECT Name FROM Name", Null, 1, TableView1)

I honestly have no idea why it still displays the last record.
 
Upvote 0

rwblinn

Well-Known Member
Licensed User
Longtime User
Hi,

change the Limit from 1 to 0 in ExecuteTableView and the records are shown. Just tested in a sample app.

B4X:
DBUtils.ExecuteTableView(TheSQL, "SELECT Name FROM Name", Null, 0, TableView1)
 
Upvote 0

LWGShane

Well-Known Member
Licensed User
Longtime User
@rwblinn
@Eumel

It works! Thanks! (I'm switching to DBUtils for all my SQL needs; and after this test, DBUtils is freaking awesome and super easy.)
 
Upvote 0
Top