Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sqlite.ToQmGrid - problems with escaped characters
#1
Hi Gintaras,
I am using a sqlite db to maintain a user list. Some of the names have apostrophe like "O'Connor" so I use
this before populating db table row:
Code:
Copy      Help
LastNameField.SqlEscape

To look at all table entries, I fill a QM grid with the table contents:

Code:
Copy      Help
DlgGrid g0.Init(hDlg 1005);;Enrollment Gridt_db.ToQmGrid(g0 "SELECT * FROM RadEnrollment" 1);err

The problem is that the table is filled with the Escaped version e.g. "O''Conor" instead of "O'Conor".
How do I de-escape using ToQmGrid?

Thanks,
Stuart
#2
Exec unescapes '' and adds single ' to database.

Function sample_Grid_Sqlite2
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam

;Shows how to use grid control with Sqlite database.

if(hDlg) goto messages

str- t_dbfile="$desktop$\test82.db3"
Sqlite- t_db

;________________________________________________

;create database for testing
Sqlite db1.Open(t_dbfile)
db1.Exec("CREATE TABLE IF NOT EXISTS table1 (A)")
str name="O'Connor"
name.SqlEscape
db1.Exec(F"INSERT INTO table1 VALUES ('{name}')")
db1.Close
;g1
;________________________________________________


if(!ShowDialog("" &sample_Grid_Sqlite2)) ret

;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 338 135 "Dialog"
;3 QM_Grid 0x54030000 0x0 0 0 338 114 "0x0,0,0,0,0x0[]A,,,"
;1 Button 0x54030001 0x4 4 118 48 14 "OK"
;2 Button 0x54030000 0x4 56 118 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2030400 "" "" ""

ret
;messages
DlgGrid g.Init(hDlg 3)
sel message
,case WM_INITDIALOG
,;open database and add table1 to the grid control
,t_db.Open(t_dbfile)
,t_db.ToQmGrid(g "SELECT * FROM table1")
,
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
ret 1
#3
Thanks Gintaras,
I am using your example to figure this problem out. I am not familiar with the F" syntax. Where can I find this in QM?
Thanks, S
#4
F"string {variable}"

is the same as

_s.format("string %s" variable)

It is not related to databases, but convenient to use instead of format.

Help / Strings with variables
#5
Thanks so much. I didn't realize that FromQmGrid also has the SqlEscape in it so I was double escaping!
S


Forum Jump:


Users browsing this thread: 1 Guest(s)