Android Question SQL error

Discussion in 'Android Questions' started by a_carignan, Apr 8, 2015.

  1. a_carignan

    a_carignan Member Licensed User

    code here
    '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
    /code

    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?
     
    Last edited: Apr 8, 2015
  2. a_carignan

    a_carignan Member Licensed User

    code here
    '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
    /code
     
    Last edited: Apr 8, 2015
  3. Erel

    Erel Administrator Staff Member Licensed User

    Please use [code]code here...[/code] tags when posting code.
     
    lemonisdead and Peter Simpson like this.
  4. a_carignan

    a_carignan Member Licensed User

    The error seems to be intermittent.
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    Which error?
     
  6. sorex

    sorex Expert Licensed User

    I think you better stick to the old fashioned syntax like

    Code:
    insert into cartes (field1,field2) values (?,?)
    what error do you get? is it on the sql execution line or somewhere else?
     
  7. sorex

    sorex Expert Licensed User

    you didn't place quotes for the string elements

    Code:
    sql1.ExecNonQuery2("insert into cartes values ('?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?')",liste_arg)
    but like I said before defining which value belongs to which field would help you out better to figure out where to place quotes
     
  8. a_carignan

    a_carignan Member Licensed User

    The fault line is the first line reading in the database given. The error is the same if I try to read a number or a string.
    carte.nom = cursor1.GetString ("name")
     
  9. a_carignan

    a_carignan Member Licensed User

    Error exexeption is java.lang.illigalStateException: Couldn't read row 0, col,0 from CursorWindow. Make sure the cursor is initialized correctly before accessing data from it.
     
  10. Erel

    Erel Administrator Staff Member Licensed User

  11. a_carignan

    a_carignan Member Licensed User

    The command line 'cursor1.Position = a' already exists, what more?
     
  12. DonManfred

    DonManfred Expert Licensed User

    It is not in the code you posted!

    try to make sure you are using a new carte each time.
    Put a
    Code:
    dim carte as whatever
    before this line
     
  13. a_carignan

    a_carignan Member Licensed User

    The writing seems correct, since the file is readable computer. Playback looks fine since reading a file created by a computer. In addition, most of the time the code reads the cards correctly, but every once in a while the file is unreadable.
     
  14. a_carignan

    a_carignan Member Licensed User

    /new code write
    for a =0 to liste_cartes.size-1
    carte=liste_cartes.get(a)
    sql1.ExecNonQuery2("insert into cartes values ('"&carte.nom.Replace("'","''")&"',"&carte.pos&",'"&renamefile_forwrite(carte.directory).Replace("'","''")&"','"&renamefile_forwrite(carte.jpeg).Replace("'","''")&"','"&renamefile_forwrite(carte.html).Replace("'","''")&"','"&carte.web_code.Replace("'","''")&"',"&writeboolean(carte.reversible)&","&writeboolean(carte.inverser)&","&carte.bottom&","&carte.box_left&","&carte.box_top&","&carte.height&","&carte.left&","&carte.right&","&carte.top&","&carte.widht&",?)",Array As Object(savebitmaptoblob(carte.image)))
    next
    /end code
    Same probleme when reading.
     
  15. a_carignan

    a_carignan Member Licensed User

    /new code reading
    cursor1=sql1.ExecQuery("select name,pos,directory,jpeg,html,web_code,reversible,inverser,bottom,box_left,box_top,height,left,right,top,widht 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"))
    'carte.image=Main.icon
    liste_cartes.add(carte)
    Next
    cursor1.close
    For a =0 To liste_cartes.Size-1
    'Msgbox(a,Main.Titre)
    Dim carte As type_carte=liste_cartes.Get(a)
    cursor1=sql1.ExecQuery("select * from cartes where pos="&carte.pos&" order by pos")
    If cursor1.RowCount=1 Then
    cursor1.Position=0
    carte.image=Loadbitmapfromblob(cursor1.getBlob("image"))
    liste_cartes.Set(a,carte)
    Else
    Return onerrordatabase("Il y a plus qu'une carte avec la position "&a)
    End If
    Next
    cursor1.close
    /end code

    /new code saveimagetoblob
    Sub savebitmaptoblob(image As Bitmap) As Byte()
    Dim OutputStream1 As OutputStream
    Dim Buffer() As Byte
    OutputStream1.InitializeToBytesArray(1000)
    image.WriteToStream(OutputStream1,50,"JPEG")
    Buffer=OutputStream1.ToBytesArray
    Return Buffer
    End Sub
    /end code

    This seems to have fixed the problem. I feel that the images had too much quality to be read correctly.
     
  16. DonManfred

    DonManfred Expert Licensed User

    USE CODE TAGS!!!

    Edit: Forget it; i just put you on my ignore-list. Dont want to see any post without using code tags from you
     
    Last edited by a moderator: Apr 30, 2015
    lemonisdead likes this.
  17. LucaMs

    LucaMs Expert Licensed User

    upload_2015-4-30_8-13-38.png

    upload_2015-4-30_8-11-4.png


    Code:
    cursor1=sql1.ExecQuery("select name,pos,directory,jpeg,html,web_code,reversible,inverser,bottom,box_left,box_top,height,left,right,top,widht 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"))
    'carte.image=Main.icon
    liste_cartes.add(carte)
    Next
    cursor1.close
    For a =0 To liste_cartes.Size-1
    'Msgbox(a,Main.Titre)
    Dim carte As type_carte=liste_cartes.Get(a)
    cursor1=sql1.ExecQuery(
    "select * from cartes where pos="&carte.pos&" order by pos")
    If cursor1.RowCount=1 Then
    cursor1.Position=
    0
    carte.image=Loadbitmapfromblob(cursor1.getBlob(
    "image"))
    liste_cartes.Set(a,carte)
    Else
    Return onerrordatabase("Il y a plus qu'une carte avec la position "&a)
    End If
    Next
    cursor1.close
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice