Android Question SQLiteLight2 Example

Discussion in 'Android Questions' started by Roger Daley, May 25, 2019.

  1. Roger Daley

    Roger Daley Well-Known Member Licensed User

    Hi All,

    Getting nowhere with SQL example.
    Started Example2, threw up error when I tried to ADD an entry. I had entered the three inputs it said I had entered four.

    I retried in Debug, same message with the B4A line number. A mobile screen shot attatched.
    The error log is below:

    All I've done so far is update the Manifest to version 26 and added #BridgeLogger: True.

    Any clues on how to get the example to work.

    Thanks in advance Roger


    Attached Files:

  2. mangojack

    mangojack Well-Known Member Licensed User

    The reason for this error is your Insert statement is supplying an Array of 4 Values to be inserted ...
    but the Persons table has only 3 columns / fields.

    The Insert statement does contain 4 Values .. the first Value 'NULL' is still treated as a value/parameter . On Inserts ... when Null is passed as the ID value , the table ID will auto increase by 1.

    Ps: In the original example Persons table does have 4 fields (persons.db in Assets file) .. You have not altered the db in any way ?
    If you still have an issue it might be better to upload your example to make it easier to solve your problem.
    Last edited: May 25, 2019
  3. Roger Daley

    Roger Daley Well-Known Member Licensed User

    Thanks Mangojack,

    The only changes I have made are what I said in the original post.

    The code is from Klaus' booklet on SQL {Tutorial} which I hoped would get me started.
    I am guessing that when you say 4 values you refer to "Query = "INSERT INTO persons VALUES (NULL, ?, ?, ?)"".
    I have no idea of the number of fields as the reason I loaded this example was to start on SQL.

    I have attached the file.

    Regards Roger

    Attached Files:

  4. mangojack

    mangojack Well-Known Member Licensed User

    I did have an error at first (read only db issue) but it was caused by extra unneeded lines in the starter Service_Create sub.

    Edit the Starter Service Sub to read as follows ...
    Sub Service_Create
    'File.Delete(File.DirInternal, "persons.db") ' only for testing, removes the database
    'check if the database already exists
        If File.Exists(File.DirInternal, "persons.db") = False Then
    'copy the default DB
            File.Copy(File.DirAssets, "persons.db"File.DirInternal, "persons.db")
    'and initialize it
            SQL1.Initialize(File.DirInternal, "persons.db"True)
    'db does exist ... so just initialize it
            SQL1.Initialize(File.DirInternal, "persons.db"True)
    End If
    End Sub
    After this change your uploaded example worked fine ..

    ps: If you do have an issue ... I would run the File.Delete line once , then comment it back out.

    pps: Download this db utility to look inside the persons db (project folder / files ) ....
    Last edited: May 25, 2019
  5. mangojack

    mangojack Well-Known Member Licensed User

    This appears to be a more updated version ... maybe wise to completely ditch your version and have a fresh start. ;)

    ps: I would still edit the starter Service_Create to read as in above post.
    Last edited: May 25, 2019
  6. Roger Daley

    Roger Daley Well-Known Member Licensed User

    Klaus said he needed to update the booklet when he answered a query on SQL1 earlier this month.
    I think it is time for me to delete the complete folder of source code and start again.
    I've been trying to get in to this for the past few months but life keeps getting in the way. Fresh start tomorrow.
  7. klaus

    klaus Expert Licensed User

    There were several bugs in the program.
    Below an updated version.
    Sorry for the trouble :).

    The program in your post #3 is an old one.
    It's not the program shiped with the B4X SQLite Database Booklet.

    Attached Files:

    mangojack likes this.
  8. Roger Daley

    Roger Daley Well-Known Member Licensed User

    Thanks Klaus.
  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