Sign in Join

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

Mailing lists / lazarus / 2008-11

MYSQL setup

16 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

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

Eric March

Hello
I have MYSQL installed and running.
I think I need to install something into Lazarus so I can connect etc to DataBases.
I have followed source advice but can't connect.

Can anyone help and/or is there a manual?

Eric March
Adelaide
South Australia

Reply by email

Joost van der Sluis
to Eric March

Op donderdag 20-11-2008 om 20:37 uur [tijdzone +1030], schreef Eric March:

Show quoted text 24 lines
Malcolm Poole wrote: > Eric March wrote: > > > Hello > > I have MYSQL installed and running. > > I think I need to install something into Lazarus so I can connect etc to > > DataBases. > > I have followed source advice but can't connect. > > > > Can anyone help and/or is there a manual? > > > Can you tell us what you have tried so far with Lazarus? > > Have you followed the guidance at > http://wiki.lazarus.freepascal.org/Lazarus_Database_Tutorial ? > > Malcolm > _______________________________________________ > Lazarus mailing list > > http://www.lazarus.freepascal.org/mailman/listinfo/lazarus > Yes I have, but it assumes that I can connect. If I follow the source to connect it does not work

Oh, it does not work. I was already wondering what your problem was. But thanks for the clear explanation. Now we know exactly how to help you! ;)

Joost.

Reply by email

Tom Lisjac
to Eric March

Hi Eric,

Show quoted text 6 lines
I have followed source advice but can't connect. Can anyone help and/or is there a manual? Error: invalid compiler: file There must be something in my source looking for a compiler in the wrong place :-(

The errors you're getting in the tutorial example are from some hard coded paths in the database_try.lpi project file. It's not a problem with your system. Since Lazarus has changed since the example was written, it might be easier to start your project with the sqldb components.

To install sqldb, go to "Package->Open package file", select and install the lazarus/components/sqldb/sqldblaz.lpk package. After Lazarus recompiles, you should see a "SQLdb" tab. Drop a Mysql50 (TMySQL50Connection) on a new form. In the object inspector for this component, enter the hostname (probably localhost), a database (test or mysql as an example or a database you've already created) and the username and password for the database or the "root" you set when installing mysql. At this point, establishing a successful mysql connection is being able to set the Connected property to true without an error.

The next step is to add TSQLTransaction and TSQLQuery (a TDataset descendent) to your form and point them to TMySQL50Connection. TSQLQuery is used to pass DDL or DML sql statements to the database and return DML result sets. Put your sql statements in the SQL stringlist and use the ExecSQL method to execute DDL statements or the open method to return a DML result set. Adding a TDatasource to the form and pointing it at the TSQLQuery will allow you to use the data aware components to display the query results.

Marco Cantu has posted a pdf extract from "Essential Delphi" that provides a good sql overview:

http://www.marcocantu.com/edelphi/EssentialSQL_md6.pdf

Hopefully this will get you started. There books and examples on the net about using TDatasets and the data aware components.

-Tom

Reply by email

Joost van der Sluis
to Eric March

Op maandag 01-12-2008 om 16:45 uur [tijdzone +1030], schreef Eric March:

Show quoted text 37 lines
Tom Lisjac wrote: > Hi Eric, > > > > I have followed source advice but can't connect. > > Can anyone help and/or is there a manual? > > > > > > Error: invalid compiler: file > > There must be something in my source looking for a compiler in the wrong > > place :-( > > > > The errors you're getting in the tutorial example are from some hard > coded paths in the database_try.lpi project file. It's not a problem > with your system. Since Lazarus has changed since the example was > written, it might be easier to start your project with the sqldb > components. > > To install sqldb, go to "Package->Open package file", select and > install the lazarus/components/sqldb/sqldblaz.lpk package. After > Lazarus recompiles, you should see a "SQLdb" tab. Drop a Mysql50 > (TMySQL50Connection) on a new form. In the object inspector for this > component, enter the hostname (probably localhost), a database (test > or mysql as an example or a database you've already created) and the > username and password for the database or the "root" you set when > installing mysql. At this point, establishing a successful mysql > connection is being able to set the Connected property to true without > an error. > > Thanks heaps for the help. I Get this far and changing "Connected" to "True" gives the error "Cannot load MySQL library "libmysqlclient.so. Please check your installation."

Maybe we have to improve that error-message even further. You have to install MySQL to be able to work with it.

So install the mysql-client before you can use it.

On linux it could be that you also have to install the '-dev' package.

Joost

Reply by email

Joost van der Sluis
to Eric March

Op dinsdag 02-12-2008 om 20:17 uur [tijdzone +1030], schreef Eric March:

I am guessing the SQLTransaction1 needs to be set to TRUE before I can set the SQLQuery1 properties. I get (and expected) an error on SQLQuery1.

But you expected another error, that's why you dind't read it well. (Or it's too cryptic)

SQLQuery1 properties: Active = False "True" gives error = "Transaction of connection not set" (Expected)

The connection also has a 'transaction' property. You haven't set that one. In principle this isn't necessary if you set ParseSQL to false, ie: make it readonly. But that's a different story.

That you can't make a transaction active is because MySQL don't support transactions. But SQLDB enforce you to use them anyway. They are useless, but they have to be there.

Joost.

Reply by email

Tom Lisjac
to Eric March
I am still at step 2 but don't understand step 3. I can see more difficulties looming. Am I following the best path to learn db applications in Lazarus?

Some of the pages in this online book preview might be helpful. It's Delphi/Kylix oriented but many of the same principles apply:

http://books.google.com/books?id=Y98Y4qJpH8gC&printsec=frontcover&dq=tdataset+tdatasource

There are many other books on this subject and I'd suggest doing some reading before trying to create a db app. Since you've already got your database installed and the sqldb connection working, a little study is a sound investment that can prepare you to use the db-aware components for displaying data from your connection, query and datasource chain. It's actually an easy process that basically involves by dropping the data aware visual components on the form and hooking them up using the object inspector. These components work during design time, so you can verify that the db components are operational without having to compile your app.

-Tom

Reply by email

Joost van der Sluis
to Eric March: An HTML attachment was scrubbed... URL: http://www.lazarus.freepascal.org/pipermail/lazaru…

Op woensdag 03-12-2008 om 09:40 uur [tijdzone +1030], schreef Eric March:

Show quoted text 7 lines
> I have set the connection in MySQL50Connection1to SQLTransaction1 As you point out I still can't set the transaction to True, so I leave it False. Now when I set SQLQuery1 to True I get an error ".e...e" is an invalid float

Ok, that's not good. The mysql-client which you are using is version 5.0. What is the server version? And which fpc-version did you use? Maybe you could try with a fpc version 2.2.3 snapshot. And are you on 64 or 32 bit?

Joost.

Reply by email

Joost van der Sluis
to Eric March

Op donderdag 04-12-2008 om 18:40 uur [tijdzone +1030], schreef Eric March:

Show quoted text 21 lines
Joost van der Sluis wrote: > Op woensdag 03-12-2008 om 09:40 uur [tijdzone +1030], schreef Eric > March: > > > I have set the connection in MySQL50Connection1to SQLTransaction1 > > As you point out I still can't set the transaction to True, so I leave > > it False. > > > > Now when I set SQLQuery1 to True I get an error > > ".e...e" is an invalid float > > > > Ok, that's not good. The mysql-client which you are using is version > 5.0. What is the server version? And which fpc-version did you use? > Maybe you could try with a fpc version 2.2.3 snapshot. And are you on 64 > or 32 bit? > Details below: MYSQL Server version = 5.0 fpc version 2.2 Linux Ubuntu 64 bit Kernel 2.6

You have to upgrade to fpc is probably this bug
http://bugs.freepascal.org/view.php?id=10202 (or actually 8593, which is the main cause)

Joost.

Reply by email