Android Question sqlite question

Discussion in 'Android Questions' started by Charles, Mar 31, 2015.

  1. Charles

    Charles Member Licensed User

    Can anyone tell me why this query
    SELECT printf("$ %4.2f",total) FROM tickets WHERE total > 0;
    where total is type real,
    works fine ($1.00) when I run it in a sqlite db manager but when I build the exact same string in B4A using stringbuilder, it fails on the same db ?
     
  2. DonManfred

    DonManfred Expert Licensed User

    Which version of sqlite you are using?

     
    Peter Simpson likes this.
  3. Charles

    Charles Member Licensed User

    Version 3
     
  4. edgar_ortiz

    edgar_ortiz Active Member Licensed User

    Charles,

    Consider that sqlite is not the place to do output formatting

    You can easy format in B4A

    Regards,

    Edgar
     
    DonManfred likes this.
  5. Charles

    Charles Member Licensed User

    I know. I'm using a function to format the returned field before plugging it into webview.
    I was just curious why it errors out while printf is a legal sqlite function.
     
  6. Mahares

    Mahares Well Known Member Licensed User

    As Manfred indicated, the printf function was introduced in version 3.8.3 of SQLite. If your version is lower, it will not work. It is not forward compatible. My device has a version of: 3.8.6. and the function works for me; see my below code:
    Code:
    txt="SELECT printf('$ %4.2f',total) AS F_total FROM tickets WHERE total > 0"
    Cursor1=SQL1.ExecQuery(txt)
            
    For i=0 To Cursor1.RowCount-1
            Cursor1.Position=i
                
    Log (Cursor1.GetString("F_total") )      'example: displays: $ 4.20 or $ 8234.00
            Next
     
  7. keirS

    keirS Well-Known Member Licensed User

    The only version of Android that support's printf is Lollipop.
     
  8. Charles

    Charles Member Licensed User

    That explains it keirS. I'm coding for version 4.2.2
     
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