Charles Member Licensed User Longtime User Mar 31, 2015 #1 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 ?
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 ?
DonManfred Expert Licensed User Longtime User Mar 31, 2015 #2 Which version of sqlite you are using? printf was added as a core function in version 3.8.3 of sqlite3. This information can be found in these release notes: 2014-02-03 (3.8.3) Added support for common table expressions and the WITH clause. Added the printf() SQL function. Click to expand... Upvote 0
Which version of sqlite you are using? printf was added as a core function in version 3.8.3 of sqlite3. This information can be found in these release notes: 2014-02-03 (3.8.3) Added support for common table expressions and the WITH clause. Added the printf() SQL function. Click to expand...
E edgar_ortiz Active Member Licensed User Longtime User Mar 31, 2015 #4 Charles, Consider that sqlite is not the place to do output formatting You can easy format in B4A Regards, Edgar Upvote 0
Charles, Consider that sqlite is not the place to do output formatting You can easy format in B4A Regards, Edgar
Charles Member Licensed User Longtime User Mar 31, 2015 #5 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. Upvote 0
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.
M Mahares Expert Licensed User Longtime User Mar 31, 2015 #6 Charles said: I was just curious why it errors out while printf is a legal sqlite function. Click to expand... 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: Copy 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 Upvote 0
Charles said: I was just curious why it errors out while printf is a legal sqlite function. Click to expand... 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: Copy 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
K keirS Well-Known Member Licensed User Longtime User Mar 31, 2015 #7 The only version of Android that support's printf is Lollipop. Upvote 0
Charles Member Licensed User Longtime User Mar 31, 2015 #8 That explains it keirS. I'm coding for version 4.2.2 Upvote 0