Android Tutorial SQL tutorial

Status
Not open for further replies.

sorex

Expert
Licensed User
Longtime User
Erel,

the code below is a copy from post #1 here.

why do you switch from SQL1. to SQL. ?

Is that a typo?

SQL1.BeginTransaction
Try
'Execute the sql statements.
SQL.TransactionSuccessful
Catch
'the transaction will be cancelled
End Try
SQL.EndTransaction
 

haddad

Member
Licensed User
Longtime User
with sqllite he don't knenw * , then you must do "SELECT FROM nametable"
 

schemer

Active Member
Licensed User
Longtime User
I started making my SQLite DB a year or two ago for a VB6 app but never finished it (to replace the hard coded data in the app) and now I am going to finish it for B4A app conversion. I am new to B4A (bought on 01-21-2015) and pretty much SQLite too. I looked at my db in SQLite and see I have used the DECIMAL(6,4) data type for one column of data. From what I have read I think I need to change the data type to REAL. Is that correct?
Thanks,
schemer
 

TheFalcon

Active Member
Licensed User
Longtime User
a question, how can you use the SQL date when I table the date type are not available, and when it is necessary to add to the list and put it as Array of String when using Sql.Query can not order Date DESC that date is as Type TEXT

B4X:
tabla_lista.Add(Array As String(fecha_informe, peso_informe, tipo_informe))

I add values to a Listview but the date to be formatted TEXT not accept me consulting By Desc order
Thanks
 

a_carignan

Member
Licensed User
Longtime User
Code for save
For a =0 To liste_cartes.Size-1
carte=liste_cartes.Get(a)
liste_arg.Clear
liste_arg.Add(carte.nom)
liste_arg.Add(carte.pos)
liste_arg.Add(renamefile_forwrite(carte.directory))
liste_arg.Add(renamefile_forwrite(carte.jpeg))
liste_arg.Add(renamefile_forwrite(carte.html))
liste_arg.Add(carte.web_code)
liste_arg.Add(writeboolean(carte.reversible))
liste_arg.Add(writeboolean(carte.inverser))
liste_arg.Add(carte.bottom)
liste_arg.Add(carte.box_left)
liste_arg.Add(carte.box_top)
liste_arg.Add(carte.height)
liste_arg.Add(carte.left)
liste_arg.Add(carte.right)
liste_arg.Add(carte.top)
liste_arg.Add(carte.widht)
liste_arg.Add(savebitmaptoblob(carte.image))
sql1.ExecNonQuery2("insert into cartes values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",liste_arg)
Next

Code for read
cursor1=sql1.ExecQuery("select * from cartes order by pos")
If cursor1.RowCount>0 Then
liste_cartes.Clear
For a =0 To cursor1.RowCount-1
cursor1.Position=a
Dim carte As type_carte
carte.Initialize
carte.nom=cursor1.GetString("name")
carte.pos=cursor1.GetLong("pos")
carte.directory=renamefile_forread(cursor1.GetString("directory"))
carte.jpeg=renamefile_forread(cursor1.GetString("jpeg"))
carte.html=renamefile_forread(cursor1.GetString("html"))
carte.web_code=cursor1.GetString("web_code")
carte.reversible=readboolean(cursor1.GetInt("reversible"))
carte.inverser=readboolean(cursor1.Getint("inverser"))
carte.bottom=cursor1.Getint("bottom")
carte.box_left=cursor1.Getint("box_left")
carte.box_top=cursor1.Getint("box_top")
carte.height=cursor1.Getint("height")
carte.left=cursor1.Getint("left")
carte.right=cursor1.Getint("right")
carte.top=cursor1.Getint("top")
carte.widht=cursor1.Getint("widht")
carte.image=Loadbitmapfromblob(cursor1.getBlob("image"))
liste_cartes.add(carte)
Next

Explain to me why the second card is unreadable on the phone. But on the computer all the cards are read well. The version of the computer will read well on the phone too. Only the written version of the phone unreadable by the phones.
Explinations?
 

a_carignan

Member
Licensed User
Longtime User
Here is the new code, and it fixed the problem.
sql1.BeginTransaction
Try
For a =0 To liste_cartes.Size-1
carte=liste_cartes.Get(a)
liste_arg.Clear
liste_arg.Add(carte.nom)
liste_arg.Add(carte.pos)
liste_arg.Add(renamefile_forwrite(carte.directory))
liste_arg.Add(renamefile_forwrite(carte.jpeg))
liste_arg.Add(renamefile_forwrite(carte.html))
liste_arg.Add(carte.web_code)
liste_arg.Add(writeboolean(carte.reversible))
liste_arg.Add(writeboolean(carte.inverser))
liste_arg.Add(carte.bottom)
liste_arg.Add(carte.box_left)
liste_arg.Add(carte.box_top)
liste_arg.Add(carte.height)
liste_arg.Add(carte.left)
liste_arg.Add(carte.right)
liste_arg.Add(carte.top)
liste_arg.Add(carte.widht)
liste_arg.Add(savebitmaptoblob(carte.image))
sql1.ExecNonQuery2("insert into cartes values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",liste_arg)
Next
sql1.TransactionSuccessful
Catch
Log(LastException.Message)
End Try
sql1.EndTransaction
 

Alberto Michelis

Well-Known Member
Licensed User
Longtime User
Hi,
1) How to know if a table exists or not?
I need to create a teble if it does not exists.
2) Any win utility to edit the .db files?

Thanks
 

Alberto Michelis

Well-Known Member
Licensed User
Longtime User
How to change the data folder name?

I change the project name to armi.portit and I get

/storage/emulated/0/Android/data/armi.portit/files

but, where are this storage folder located?

I cant locate it in Phone/Android/Data

Thanks
 
Last edited:

Ferbis

Active Member
Licensed User
Longtime User
Read my post "Good Database Manager for programming with B4A" for the win DBB utilities

I suggest you to read the Beginners Guide and the User Guide to start with b4a. Beleave me if I say that it is not a waste of time. They are fantastic!!!
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…