Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2012-12

TSQLQuery Error Database not assigned.

4 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Giuliano Colla

I'm trying to familiarize with MySql components, using mysql 5.1. I downloaded the TryMySql example linked from the Wiki page, I've changed TMySQL50Connection to TMySQL51Connection, and set in SQLQuery ParseSQL=False and ReadOnly=true, as suggested, but when I try to run it, the "connect to server" fails with the error "Database not assigned!". The code I'm using is:

   MySQLConnection1.HostName := HostEdit.Text;
   MySQLConnection1.UserName := UserEdit.Text;
   MySQLConnection1.Password := PasswdEdit.Text;
   MySQLConnection1.DatabaseName := 'mysql'; // MySQL is allways there!
   ShowString('Opening a connection to server: ' + HostEdit.Text);
   MySQLConnection1.Open;
   // First lets get a list of available databases.
   if MySQLConnection1.Connected then begin
     ShowString('Connected to server: ' + HostEdit.Text);
     ShowString('Retreiving list of available databases.');
     SQLQuery1.SQL.Text := 'show databases';
     SQLQuery1.Open; <==== Fails here

This occurs both with Lazarus 1.02 and with Lazarus svn (rev.39655), and fpc 2.6.0, in Linux (FC14) environment.
Useless to say that mysql from command line, with identical parameters works as expected.
Am I doing something wrong, should I use fpc 2.6.1, set some extra parameter, or what?

Any help is welcome!

Giuliano

Reply by email

Michael Van Canneyt
to Giuliano Colla
Giuliano Colla wrote 20 lines
I'm trying to familiarize with MySql components, using mysql 5.1. I downloaded the TryMySql example linked from the Wiki page, I've changed TMySQL50Connection to TMySQL51Connection, and set in SQLQuery ParseSQL=False and ReadOnly=true, as suggested, but when I try to run it, the "connect to server" fails with the error "Database not assigned!". The code I'm using is: MySQLConnection1.HostName := HostEdit.Text; MySQLConnection1.UserName := UserEdit.Text; MySQLConnection1.Password := PasswdEdit.Text; MySQLConnection1.DatabaseName := 'mysql'; // MySQL is allways there! ShowString('Opening a connection to server: ' + HostEdit.Text); MySQLConnection1.Open; // First lets get a list of available databases. if MySQLConnection1.Connected then begin ShowString('Connected to server: ' + HostEdit.Text); ShowString('Retreiving list of available databases.'); SQLQuery1.SQL.Text := 'show databases'; SQLQuery1.Open; <==== Fails here
Did you set
  SQLQuery1.Database:=MySQLConnection1;

?

Also 'Show databases' will - to my knowlegde - not work. It is not valid SQL. as far as I know, it's a metadata statement that is handled by the mysql client which translates it to an API call.

Michael.

Reply by email

William Oliveira Ferreira
to Michael Van Canneyt

Another point is add a transaction on your project and assign it to sqlconnection...

At least, i never connected without a transaction ....

"Michael Van Canneyt" wrote 7 lines
On Wed, 26 Dec 2012, Giuliano Colla wrote: > I'm trying to familiarize with MySql components, using mysql 5.1. > I downloaded the TryMySql example linked from the Wiki page, I've

changed TMySQL50Connection to TMySQL51Connection, and set in SQLQuery ParseSQL=False and ReadOnly=true, as suggested, but when I try to run it, the "connect to server" fails with the error "Database not assigned!".

Show quoted text 23 lines
> The code I'm using is: > > MySQLConnection1.HostName := HostEdit.Text; > MySQLConnection1.UserName := UserEdit.Text; > MySQLConnection1.Password := PasswdEdit.Text; > MySQLConnection1.DatabaseName := 'mysql'; // MySQL is allways there! > ShowString('Opening a connection to server: ' + HostEdit.Text); > MySQLConnection1.Open; > > // First lets get a list of available databases. > if MySQLConnection1.Connected then begin > ShowString('Connected to server: ' + HostEdit.Text); > ShowString('Retreiving list of available databases.'); > SQLQuery1.SQL.Text := 'show databases'; > SQLQuery1.Open; <==== Fails here Did you set SQLQuery1.Database:=MySQLConnection1; ? Also 'Show databases' will - to my knowlegde - not work. It is not valid

SQL.

as far as I know, it's a metadata statement that is handled by the mysql

client which translates it to an API call.

Show quoted text 9 lines
Michael. -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20121226/ac3d1e55/attachment.html>

Reply by email

Giuliano Colla
to William Oliveira Ferreira

Il 26/12/2012 15:53, William Oliveira Ferreira ha scritto:

Show quoted text 18 lines
Another point is add a transaction on your project and assign it to sqlconnection... At least, i never connected without a transaction .... > > Did you set > SQLQuery1.Database:=MySQLConnection1; > > ? > > Also 'Show databases' will - to my knowlegde - not work. It is not valid SQL. > as far as I know, it's a metadata statement that is handled by the mysql client which translates it to an API call. >

Thanks to both of you. Filling up SQLQuery and SQLTansaction properties (which most likely had been cleared from the example when changing TConnection from 5.0 to 5.1) now it works.

BTW "show databases" appears to work, because databases are shown.

Giuliano.

Reply by email