Recent

Author Topic: Trouble getting data from MySQL  (Read 5240 times)

criageek

  • Jr. Member
  • **
  • Posts: 79
Trouble getting data from MySQL
« on: March 01, 2007, 12:57:36 am »
I'm new to Lazarus, very experienced with Delphi.  I'm trying to build my first database app, and I'm having trouble getting any data out of the database.  I downloaded the source from this page:

http://wiki.lazarus.freepascal.org/MySQLDatabases

and I'm trying to make that work.  After changing the connection component to a TMySQL50Connection I can connect, and it looks like the query is being sent.  I'm having trouble getting the debugger to work (I have a thread in the debug forum), so I put messages at various places to get status. and it looks like the query executes without any exceptions, but when I test the "active" property it says it's closed and no data appears in the dbgrid.  If I change the query to specify an invalid table name, it fails and says the table does not exist, so I know it's talking to the database.  

Another odd thing is that I can't do "show databases" and "show tables"....it says I have a syntax error in my sql (yet I can issue these commands from "MySQL Query Browser).

I'm using Ubuntu 6.10 on the 2.6.19.3 kernel, and MySQL Administrator says I'm using server 5.0.24a-Debian_9-log and client 5.0.21.

Any ideas what's going on?

Thanks,
Rich

RudieD

  • Full Member
  • ***
  • Posts: 234
RE: Trouble getting data from MySQL
« Reply #1 on: March 01, 2007, 06:09:29 pm »
Do you use a ; at the end off the statement like in pascal like "show databases;" ?
The FRED Trainer. (Training FRED with Lazarus/FPC)

criageek

  • Jr. Member
  • **
  • Posts: 79
RE: Trouble getting data from MySQL
« Reply #2 on: March 01, 2007, 06:43:47 pm »
I've tried it both ways...no luck either way.  The error message says something like "syntax error at '' in line 1".  I'm not at home so I'm going from memory right now.

Rich

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
RE: Trouble getting data from MySQL
« Reply #3 on: March 02, 2007, 09:16:55 am »
Can you try the following? Use
Code: [Select]
SqlQuery.Execute; to execute the query.

You can also try to set SqlQuery.ParseSQL := false;

Please update the wiki, if you get it working.

Disclaimer: I haven't tried this and I am not even sure about the exact method and property names.

criageek

  • Jr. Member
  • **
  • Posts: 79
RE: Trouble getting data from MySQL
« Reply #4 on: March 02, 2007, 05:00:32 pm »
Thanks for the tips Vincent.  I finally got this working, but I'm not completely sure what did it.  The way I have it now, I have to have a valid SQL statement in my TSQLQuery component, and I have to open the query in the FormCreate event.  If I don't do both of those, I get the exception detailed above when I try to do a query (with the same TSQLQuery component) later.  If I do both if I don't  of those it works fine.

Rich

criageek

  • Jr. Member
  • **
  • Posts: 79
Re: RE: Trouble getting data from MySQL
« Reply #5 on: March 03, 2007, 02:30:19 pm »
Quote from: "rdfrahm"
Thanks for the tips Vincent.  I finally got this working, but I'm not completely sure what did it.  The way I have it now, I have to have a valid SQL statement in my TSQLQuery component, and I have to open the query in the FormCreate event.  If I don't do both of those, I get the exception detailed above when I try to do a query (with the same TSQLQuery component) later.  If I do both if I don't  of those it works fine.

Rich

Oops...I'll finish that last sentence properly.

"If I do both of those things, it works fine."

Rich

 

TinyPortal © 2005-2018