Subject | Re: Trouble with Insert Into |
---|---|
Author | squidsrus85 |
Post date | 2011-08-14T21:27:42Z |
Hi Markus,
Thanks for the detailed reply. Didn't know about DDL and DML, but I can see why it is balking now. Thanks. I knew it had to be something I was doing wrong.
In my dbf to FDB import I am creating the table before the import.
because I am testing this it will run many times before I get it right I am guessing. {grin} In that case I am creating the table every time I try to import.
I found online how to detect if the table exists, but the RECREATE sounds like a better alternative. I used this code but modified it to Drop if the table exists.
http://www.firebirdfaq.org/faq69/
My process does the same, but with RECREATE I will not have to code it. Always a good thing. Here's what I had, Q is a Constant for single-quote character. I used the aStr instead of a direct Add( so that I can Watch it and make sure the String looked correct...
try
qry_DB.Active:=False;
qry_DB.SQL.Clear;
qry_DB.SQL.Add('EXECUTE BLOCK AS BEGIN');
aStr:='if (exists(select 1 from rdb$relations where rdb$relation_name = '+Q+'edFDBTable.Text'+Q+')) then';
qry_DB.SQL.Add(aStr);
aStr:='execute statement '+Q+'drop table '+edFDBTable.Text+';'+Q+';';
qry_DB.SQL.Add(aStr);
qry_DB.SQL.Add('END');
qry_DB.Active:=True;
OK:=True; // Used later
finally
qry_DB.SQL.Clear;
end;
It was after this, the table is then created, and crashing, but now that I know about the DDL, I am sure it will all go well.
Thanks so much. Very much appreciated.
Dave
Thanks for the detailed reply. Didn't know about DDL and DML, but I can see why it is balking now. Thanks. I knew it had to be something I was doing wrong.
In my dbf to FDB import I am creating the table before the import.
because I am testing this it will run many times before I get it right I am guessing. {grin} In that case I am creating the table every time I try to import.
I found online how to detect if the table exists, but the RECREATE sounds like a better alternative. I used this code but modified it to Drop if the table exists.
http://www.firebirdfaq.org/faq69/
My process does the same, but with RECREATE I will not have to code it. Always a good thing. Here's what I had, Q is a Constant for single-quote character. I used the aStr instead of a direct Add( so that I can Watch it and make sure the String looked correct...
try
qry_DB.Active:=False;
qry_DB.SQL.Clear;
qry_DB.SQL.Add('EXECUTE BLOCK AS BEGIN');
aStr:='if (exists(select 1 from rdb$relations where rdb$relation_name = '+Q+'edFDBTable.Text'+Q+')) then';
qry_DB.SQL.Add(aStr);
aStr:='execute statement '+Q+'drop table '+edFDBTable.Text+';'+Q+';';
qry_DB.SQL.Add(aStr);
qry_DB.SQL.Add('END');
qry_DB.Active:=True;
OK:=True; // Used later
finally
qry_DB.SQL.Clear;
end;
It was after this, the table is then created, and crashing, but now that I know about the DDL, I am sure it will all go well.
Thanks so much. Very much appreciated.
Dave