I'm using Delphi7 with MySQL 5 and a fresh copy of the latest testing branch of zeoslib (revision 378, I think). Protocol is mysql-5.
I'm trying to demonstrate runtime creation of a table. I use a TZSQLProcessor to run a 'create table' query (listed below), and then try to fill the table data via a TZTable component (with cached updated enabled):
Code: Select all
// mysql table name:
NameStr := MySqlConnection.Database + '.' + MySqlTable.TableName;
// create mysql table:
TableList := TStringList.Create;
try
MySqlConnection.Connect;
MySqlConnection.GetTableNames(MySqlTable.TableName, TableList);
if (TableList.Count > 0) then
ShowMessage('mysql: table ''' + NameStr + ''' already exists.')
else
begin
ShowMessage('mysql: table ''' + NameStr + ''' not found. creating....');
CreateTableProcessor.Connection := MySqlConnection;
CreateTableProcessor.Execute;
end;
finally
FreeAndNil(TableList);
end;
// temporary fix for insert problem:
{ MySqlConnection.Disconnect;
MySqlConnection.Connect;{}
// load mysql table:
ShowMessage('mysql: loading existing data from table ''' + NameStr + '''...');
MySqlTable.Active := True;
// populate mysql table:
if (not MySqlTable.IsEmpty) then
ShowMessage('mysql: table ''' + NameStr + ''' already contains data.')
else
with MySqlTable do
begin
ShowMessage('mysql: inserting data into table ''' + NameStr + '''...');
DisableControls;
Append;
Fields[1].AsInteger := 5;
Fields[2].AsString := 'five';
Append;
Fields[1].AsInteger := 12;
Fields[2].AsString := 'twelve';
Append;
Fields[1].AsInteger := 40;
Fields[2].AsString := 'fourty';
Append;
Fields[2].AsString := 'zero';
Post;
ApplyUpdates;
EnableControls;
end;
Code: Select all
CREATE TABLE sqlitetest (
Id INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL,
IntData INTEGER DEFAULT 0,
TextData CHAR(10)
);
MySqlConnection.Disconnect;
MySqlConnection.Connect;
immediately after creating the table, then the insert runs just fine. If I run the program when the table already exists, it also works fine. But calling MySqlConnection.Reconnect instead of Disconnect and Connect doesn't fix the problem.
One final note: before I tried the latest testing branch, I was using 6.6.2rc, and then I was getting a 'Cannot update this query type' exception during the ApplyUpdates call (with the same code). Iirc it was raised in TZGenericCachedResolver.DefineTableName.