Recent

Author Topic: Is there somebody who has a working gettablenames sample?  (Read 7338 times)

rvk

  • Hero Member
  • *****
  • Posts: 3842
Re: Is there somebody who has a working gettablenames sample?
« Reply #15 on: March 11, 2016, 07:44:15 pm »
@rvk: no it doesn't create that. But the odd thing is that you will need the appropiate db component on the form to get access to it's prototype. Otherwise the connector doesn't work.
It does. It create a "Proxy"-connection internally (you can see that in the source). FProxy in TSQLConnector is filled with the correct TMySQLXXConnection. It is used in TSQLConnector for lots of things.

Only problem is that TSQLConnector doesn't implement gettablenames and as a consequence the gettablenames of TSQLConnection is used. That in turn uses GetDBInfo() in which there is no Proxy so the actual TMySQLXXConnection is never used for the gettablenames.

Only TMySQLXXConnection has a direct override for gettablenames which handles this correctly.

B.T.W. did you include mysql55conn, mysql51conn etc in your uses clause? I think it is necessary for the registering of those TMySQLXXConnections (but I could be wrong).
« Last Edit: March 11, 2016, 07:49:18 pm by rvk »

LacaK

  • Hero Member
  • *****
  • Posts: 577
Re: Is there somebody who has a working gettablenames sample?
« Reply #16 on: March 12, 2016, 08:54:53 am »
I thought the TSQLConnection automatically created a TMySQL50Connection according to the ConnectorType but apparently it doesn't work like that.

IMO TSQLConnector creates TSQLConnection based on ConnectorType.
Try TSQLConnector.Proxy ...

@aducom: can you try TSQLConnector.Proxy.GetTableNames ?

rvk

  • Hero Member
  • *****
  • Posts: 3842
Re: Is there somebody who has a working gettablenames sample?
« Reply #17 on: March 12, 2016, 02:18:54 pm »
Yes, I already mentioned the Proxy-connection in TSQLConnector.
The problem is that FProxy is a private property.

The TSQLConnector.GetTableNames works for SQLite because the default version of GetTableNames in TSQLConnection is apparently written for SQLite. I'm not even sure why TSQLConnection even has a GetTableNames because it should be an abstract class from which the others are made.

So TSQLConnector.GetTableNames should probably be overridden and use the one from FProxy.

I can't override TSQLConnector to get to the FProxy because it's private.

Fastest way I can think of is creating your own GetTableNames and calling GetDBInfo() directly but in that case it will fail again if you use this with anything else but MySQL.
Code: Pascal  [Select]
  1. type
  2.   TMySQLConnector = class(TSQLConnector)
  3.   public
  4.     procedure myGetTableNames(List : TStrings; SystemTables : Boolean = false);
  5.   end;
  6.  
  7. procedure TMySQLConnector.myGetTableNames(List : TStrings; SystemTables : Boolean = false);
  8. begin
  9.   GetDBInfo(stTables,'','tables_in_'+DatabaseName,List)
  10. end;

Because this is not a real solution I submitted this issue (with solution) to the bugtracker:
http://bugs.freepascal.org/view.php?id=29819

LacaK

  • Hero Member
  • *****
  • Posts: 577
Re: Is there somebody who has a working gettablenames sample?
« Reply #18 on: March 12, 2016, 03:07:44 pm »
if you call TSQLConnector.GetTableNames then TSQLConnector.GetDBInfo is called.
GetDBInfo sets required schemaInfo and opens "metadata dataset"
While preparing this "metadata dataset" GetSchemaInfoSQL is called.
There is overriden GetSchemaInfoSQL for TSQLConnector, which calls FProxy.GetSchemaInfoSQL
It seems me okay ... but may be that here is any problem I will check next week ...

rvk

  • Hero Member
  • *****
  • Posts: 3842
Re: Is there somebody who has a working gettablenames sample?
« Reply #19 on: March 12, 2016, 04:23:08 pm »
Then my first question would be... why is there a separate GetTableNames in the TMySQLXXConnections? If the GetSchemaInfoSQL takes care of it all it shouldn't be necessary.

I've looked a bit further and it seems like the GetSchemaInfoSQL() of the TMySQL56Connection does indeed gets called. Also MySQL doesn't support getting system-tables so calling GetTableNames should give the mentioned error (not available).

But... calling GetTableNames with false (for usertables) still gives an error.
That's because the GetTabeNames of TSQLConnection fills in a "Returnfield" parameter with "table_name". Like this:
Code: Pascal  [Select]
  1.   GetDBInfo(stTables,'','table_name',List)
For the TMySQLXXConnections however the returnfield is "tables_in_databasename". You can see that because the GetTableNames in TMySQLXXConnection does this:
Code: Pascal  [Select]
  1.   GetDBInfo(stTables,'','tables_in_'+DatabaseName,List)

Oh, AND ADDITIONAL:
Same as above also goes for TSQLConnector.GetFieldNames(TableName, TStrings)
 : Field not found : "column_name".

(I added it to the bug-entry as comment.)

rvk

  • Hero Member
  • *****
  • Posts: 3842
Re: Is there somebody who has a working gettablenames sample?
« Reply #20 on: March 14, 2016, 05:19:05 pm »
@aducom, The issue with GetTableNames() and GetFieldNames() with TSQLConnector i.c.w. MySQL5+ is now fixed in trunk (FPC 3.1.1) by LacaK.
http://bugs.freepascal.org/view.php?id=29819
(it could take a while before it is in a stable release version)