[fpc-pascal] MySQL insert, load data
wolfram.klaeger at web.de
Fri Feb 15 12:33:27 CET 2008
Ok. First one was simple. Keyword and opening bracket must be separated
by a blank, e.g.
'.. MYTABLE(..' // wrong
'.. MYTABLE (..' // great
'..)values(..' // wrong
'..) values (..' // great
All field contents have to be bracketed by double apostrophes, e.g.
except it's an integer value, e.g.
Date values seem to be put as formatted strings. Unfortunately, my MySQL
does not know Joost. His example, '1-jan-1975' works here as '1975.1.1'
only. Guess this is a config issue.
Now what about LOAD DATA?
I still have no idea where to look for it. I learned TSQLQuery is
descending Tbufdataset <- TDBDataSet <- TDataset <- TComponent and
assume there is somewhere an option to load from a CSV text file or stream.
But how to push it forward to MySQL?
// Wolfram Kläger, 14.02.2008 22:49
> Along Joost's examples I managed to get connected, create a table, put a
> query, get the result, and insert a single row. But when I try to insert
> several rows at once, I get an EDatabaseError "near" to first char of
> second row.
> q.Add('insert into MYTABLE(c1, c2, ..) values ');
> q.Add('(r1v1, r1v2, ..),');
> q.Add('(r2v1, r2v1, ..),');
> What am I missing or is multiple insert not supported?
> Alternatively, MySQL provides the LOAD DATA [LOCAL] INFILE statement. So
> far I was not able to find a special sqldb wrapper for it. Is it done
> via ExecuteDirect?
More information about the fpc-pascal