Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Updating a SQLite table using the TSQLQuery control - beginner question



Permlink Replies: 1 - Last Post: Jan 4, 2017 3:12 PM Last Post By: Jeff Overcash (...
Laurence Chiu

Posts: 1
Registered: 1/19/17
Updating a SQLite table using the TSQLQuery control - beginner question
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 4, 2017 12:07 PM
I am just getting back in Delphi programming after many years of inactivity (my last was many years with Turbo Pascl :-) ).

Anyway I thought I would start with Granny steps and went through the guide in this thread.

http://docwiki.embarcadero.com/RADStudio/Berlin/en/Tutorial:_Connecting_to_a_SQLite_Database_from_a_VCL_Application

That works fine and I can display the data in the table.

But my goal was to actually create a table and insert rows into it and this is where I am failing.

Using the same TSQLQuery control but pointing to my own table, I can read it fine. But when I try to insert rows into the table using a construct like this where the first column of the table is the key char(16) and SQL name account_key

query := 'INSERT into Account_Info values(:acct_key, :sequence, :tipe,';
query := query + ':acct1, :suffix1, :trancode, :mts, :amount, :nayme, :particulars, :analysis_code, :reference, :bank2, :branch2, :acct2, :suffix2, :pname )';
SQLQuery1.SQL.Text := query;
SQLQuery1.ExecSQL;

while the query runs OK only null values are inserted into the table.

If however I replace the SQL INSERT statement with actual literal values like this

query := 'INSERT into Account_Info values(''0398787654000'', :sequence, :tipe,';

the row inserts fine.

I have never programmed in SQL in Delphi before but from my mainframe programming days. you could just use variables in the INSERT statement. It looks like I need to somehow assign the variables values before issuing the ExecSQL statement?

I have been reading up on a ton of articles on this but so far no luck. The closest I got was to use some FieldValue property but I have no idea how to make that work

Any pointers really appreciated.

Thanks

Edited by: Laurence Chiu on Jan 4, 2017 12:07 PM

Edited by: Laurence Chiu on Jan 4, 2017 12:07 PM
Jeff Overcash (...

Posts: 1,529
Registered: 9/23/99
Re: Updating a SQLite table using the TSQLQuery control - beginner question [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 4, 2017 3:12 PM   in response to: Laurence Chiu in response to: Laurence Chiu
Laurence Chiu wrote:
I am just getting back in Delphi programming after many years of inactivity (my last was many years with Turbo Pascl :-) ).

Anyway I thought I would start with Granny steps and went through the guide in this thread.

http://docwiki.embarcadero.com/RADStudio/Berlin/en/Tutorial:_Connecting_to_a_SQLite_Database_from_a_VCL_Application

That works fine and I can display the data in the table.

But my goal was to actually create a table and insert rows into it and this is where I am failing.

Using the same TSQLQuery control but pointing to my own table, I can read it fine. But when I try to insert rows into the table using a construct like this where the first column of the table is the key char(16) and SQL name account_key

query := 'INSERT into Account_Info values(:acct_key, :sequence, :tipe,';
query := query + ':acct1, :suffix1, :trancode, :mts, :amount, :nayme, :particulars, :analysis_code, :reference, :bank2, :branch2, :acct2, :suffix2, :pname )';
SQLQuery1.SQL.Text := query;
SQLQuery1.ExecSQL;

while the query runs OK only null values are inserted into the table.

Of course not, you didn't assign values to the parameters in that statement.
All the :acct1 type things are parameters so you have to assign values to those
parameters.


If however I replace the SQL INSERT statement with actual literal values like this

query := 'INSERT into Account_Info values(''0398787654000'', :sequence, :tipe,';

the row inserts fine.

I have never programmed in SQL in Delphi before but from my mainframe programming days. you could just use variables in the INSERT statement. It looks like I need to somehow assign the variables values before issuing the ExecSQL statement?

I have been reading up on a ton of articles on this but so far no luck. The closest I got was to use some FieldValue property but I have no idea how to make that work

Any pointers really appreciated.

Thanks

Edited by: Laurence Chiu on Jan 4, 2017 12:07 PM

Edited by: Laurence Chiu on Jan 4, 2017 12:07 PM

--
Jeff Overcash (TeamB)
(Please do not email me directly unless asked. Thank You)
Learning is finding out what you already know. Doing is demonstrating that you
know it. Teaching is reminding others that they know it as well as you. We are
all leaners, doers, teachers. (R Bach)

Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02