Recent

Author Topic: [Solved] How I can clone mysql table?  (Read 1131 times)

Fossy

  • New Member
  • *
  • Posts: 20
[Solved] How I can clone mysql table?
« on: April 24, 2015, 01:04:30 pm »
Hello!!

I'm trying to clone table with Query (TSQLQuery), using freepascal text mode. I can make "Select..." querys but I have error when I try make clone table like this:

....
query.close;
query.sql.text:='CREATE TABLE '+usuario+' AS SELECT * FROM ejemplo';
query.open;
......

And I get:

An unhandled exception occurred at $0000000000450D55 : EDatabaseError : Cannot open a non-select statement $0000000000450D55 $0000000000454212 $0000000000471B2F $000000000042D10F

Please, how I can clone mysql table with freepascal?.

Thanks!!.

« Last Edit: April 28, 2015, 11:09:54 am by Fossy »

rvk

  • Hero Member
  • *****
  • Posts: 3798
Re: How I can clone mysql table?
« Reply #1 on: April 24, 2015, 01:25:51 pm »
An unhandled exception occurred at $0000000000450D55 : EDatabaseError : Cannot open a non-select statement $0000000000450D55 $0000000000454212 $0000000000471B2F $000000000042D10F
The message already says what the problem is.
query.Open needs to have a result-set. Your CREATE-command does not give any result-set back (and shouldn't). When you're doing a CREATE, DELETE, UPDATE and INSERT in SQL you need to use query.ExecSQL;

Only when you have a SELECT (which does give a result-set back) you can use query.Open.

You can read about it here:
http://wiki.freepascal.org/SqlDBHowto/nl#Hoe_voer_je_een_query_uit_met_een_TSQLQuery.3F

Fossy

  • New Member
  • *
  • Posts: 20
Re: [Solved] How I can clone mysql table?
« Reply #2 on: April 28, 2015, 11:11:29 am »
Thanks rvk!!

Works perfectly :).

Thanks!!!!