fcl-db: mysql: add support for MySQL 5.6

git-svn-id: trunk@26197 -
This commit is contained in:
lacak 2013-12-08 09:44:46 +00:00
parent dde4ec96c2
commit 29ddc3f688
8 changed files with 100 additions and 68 deletions

1
.gitattributes vendored
View File

@ -2152,6 +2152,7 @@ packages/fcl-db/src/sqldb/mysql/mysql4conn.pas svneol=native#text/plain
packages/fcl-db/src/sqldb/mysql/mysql50conn.pas svneol=native#text/plain
packages/fcl-db/src/sqldb/mysql/mysql51conn.pas svneol=native#text/plain
packages/fcl-db/src/sqldb/mysql/mysql55conn.pas svneol=native#text/plain
packages/fcl-db/src/sqldb/mysql/mysql56conn.pas svneol=native#text/pascal
packages/fcl-db/src/sqldb/mysql/mysqlconn.inc svneol=native#text/plain
packages/fcl-db/src/sqldb/odbc/Makefile svneol=native#text/plain
packages/fcl-db/src/sqldb/odbc/Makefile.fpc svneol=native#text/plain

View File

@ -4,7 +4,7 @@
unit mysql50conn;
{$DEFINE MYSQL50_up}
{$DEFINE MYSQL50_UP}
{$DEFINE MYSQL50}
{$i mysqlconn.inc}

View File

@ -4,7 +4,6 @@
unit mysql51conn;
{$DEFINE MYSQL50_UP}
{$DEFINE MYSQL51_UP}
{$DEFINE MYSQL51}

View File

@ -4,8 +4,7 @@
unit mysql55conn;
{$DEFINE MYSQL50_UP}
{$DEFINE MYSQL51_UP}
{$DEFINE MYSQL55_UP}
{$DEFINE MYSQL55}
{$i mysqlconn.inc}

View File

@ -0,0 +1,12 @@
{
Contains the TMysqlConnection for MySQL 5.6
}
unit mysql56conn;
{$DEFINE MYSQL56_UP}
{$DEFINE MYSQL56}
{$i mysqlconn.inc}
end.

View File

@ -1,3 +1,12 @@
{$IFDEF MYSQL56_UP}
{$DEFINE MYSQL55_UP}
{$ENDIF}
{$IFDEF MYSQL55_UP}
{$DEFINE MYSQL51_UP}
{$ENDIF}
{$IFDEF MYSQL51_UP}
{$DEFINE MYSQL50_UP}
{$ENDIF}
{$mode objfpc}{$H+}
@ -5,9 +14,12 @@ interface
uses
Classes, SysUtils,bufdataset,sqldb,db,ctypes,
{$IFDEF mysql55}
{$IFDEF mysql56}
mysql56dyn;
{$ELSE}
{$IFDEF mysql55}
mysql55dyn;
{$ELSE}
{$ELSE}
{$IFDEF mysql51}
mysql51dyn;
{$ELSE}
@ -17,38 +29,37 @@ uses
{$IfDef mysql41}
mysql41dyn;
{$ELSE}
{$IFDEF mysql4} // temporary backwards compatibility for Lazarus
mysql40dyn;
{$ELSE}
mysql40dyn;
{$EndIf}
mysql40dyn;
{$EndIf}
{$EndIf}
{$endif}
{$endif}
{$ENDIF}
Const
MySQLVersion =
{$IFDEF mysql56}
'5.6';
{$ELSE}
{$IFDEF mysql55}
MySQLVersion = '5.5';
{$else}
'5.5';
{$ELSE}
{$IFDEF mysql51}
MySQLVersion = '5.1';
'5.1';
{$else}
{$IfDef mysql50}
MySQLVersion = '5.0';
'5.0';
{$ELSE}
{$IfDef mysql41}
MySQLVersion = '4.1';
'4.1';
{$ELSE}
{$IFDEF mysql4} // temporary backwards compatibility for Lazarus
MySQLVersion = '4.0';
{$ELSE}
MySQLVersion = '4.0';
{$EndIf}
'4.0';
{$EndIf}
{$EndIf}
{$endif}
{$endif}
{$ENDIF}
Type
TTransactionName = Class(TSQLHandle)
protected
@ -152,6 +163,12 @@ Type
EMySQLError = Class(Exception);
{$IFDEF mysql56}
TMySQL56Connection = Class(TConnectionName);
TMySQL56ConnectionDef = Class(TMySQLConnectionDef);
TMySQL56Transaction = Class(TTransactionName);
TMySQL56Cursor = Class(TCursorName);
{$ELSE}
{$ifdef mysql55}
TMySQL55Connection = Class(TConnectionName);
TMySQL55ConnectionDef = Class(TMySQLConnectionDef);
@ -176,21 +193,15 @@ Type
TMySQL41Transaction = Class(TTransactionName);
TMySQL41Cursor = Class(TCursorName);
{$ELSE}
{$IFDEF mysql4} // temporary backwards compatibility for Lazarus
TMySQLConnection = Class(TConnectionName);
TMySQL40ConnectionDef = Class(TMySQLConnectionDef);
TMySQLTransaction = Class(TTransactionName);
TMySQLCursor = Class(TCursorName);
{$ELSE}
TMySQL40Connection = Class(TConnectionName);
TMySQL40ConnectionDef = Class(TMySQLConnectionDef);
TMySQL40Transaction = Class(TTransactionName);
TMySQL40Cursor = Class(TCursorName);
{$EndIf}
TMySQL40Connection = Class(TConnectionName);
TMySQL40ConnectionDef = Class(TMySQLConnectionDef);
TMySQL40Transaction = Class(TTransactionName);
TMySQL40Cursor = Class(TCursorName);
{$EndIf}
{$endif}
{$EndIf}
{$ENDIF}
{$ENDIF}
implementation
@ -214,9 +225,17 @@ const
{$IFDEF MYSQL50_UP}
,'MYSQL_REPORT_DATA_TRUNCATION', 'MYSQL_OPT_RECONNECT'
{$IFDEF mysql51_UP}
,'MYSQL_OPT_SSL_VERIFY_SERVER_CERT'
{$IFDEF mysql55}
,'MYSQL_PLUGIN_DIR', 'MYSQL_DEFAULT_AUTH'
,'MYSQL_OPT_SSL_VERIFY_SERVER_CERT'
{$IFDEF mysql55_UP}
,'MYSQL_PLUGIN_DIR', 'MYSQL_DEFAULT_AUTH'
{$IFDEF MYSQL56_UP}
,'MYSQL_OPT_BIND'
,'MYSQL_OPT_SSL_KEY', 'MYSQL_OPT_SSL_CERT', 'MYSQL_OPT_SSL_CA', 'MYSQL_OPT_SSL_CAPATH', 'MYSQL_OPT_SSL_CIPHER', 'MYSQL_OPT_SSL_CRL', 'MYSQL_OPT_SSL_CRLPATH'
,'MYSQL_OPT_CONNECT_ATTR_RESET', 'MYSQL_OPT_CONNECT_ATTR_ADD', 'MYSQL_OPT_CONNECT_ATTR_DELETE'
,'MYSQL_SERVER_PUBLIC_KEY'
,'MYSQL_ENABLE_CLEARTEXT_PLUGIN'
,'MYSQL_OPT_CAN_HANDLE_EXPIRED_PASSWORDS'
{$ENDIF}
{$ENDIF}
{$ENDIF}
{$ENDIF}
@ -469,6 +488,9 @@ end;
function TConnectionName.AllocateCursorHandle: TSQLCursor;
begin
{$IFDEF mysql56}
Result:=TMySQL56Cursor.Create;
{$ELSE}
{$IfDef mysql55}
Result:=TMySQL55Cursor.Create;
{$ELSE}
@ -481,15 +503,12 @@ begin
{$IfDef mysql41}
Result:=TMySQL41Cursor.Create;
{$ELSE}
{$IFDEF mysql4} // temporary backwards compatibility for Lazarus
Result:=TMySQLCursor.Create;
{$ELSE}
Result:=TMySQL40Cursor.Create;
{$EndIf}
Result:=TMySQL40Cursor.Create;
{$EndIf}
{$EndIf}
{$EndIf}
{$endif}
{$EndIf}
{$ENDIF}
end;
Procedure TConnectionName.DeAllocateCursorHandle(var cursor : TSQLCursor);
@ -1216,6 +1235,9 @@ end;
class function TMySQLConnectionDef.ConnectionClass: TSQLConnectionClass;
begin
{$IFDEF mysql56}
Result:=TMySQL56Connection;
{$ELSE}
{$IfDef mysql55}
Result:=TMySQL55Connection;
{$ELSE}
@ -1228,15 +1250,12 @@ begin
{$IfDef mysql41}
Result:=TMySQL41Connection;
{$ELSE}
{$IFDEF mysql4} // temporary backwards compatibility for Lazarus
Result:=TMySQLConnection;
{$ELSE}
Result:=TMySQL40Connection;
{$EndIf}
Result:=TMySQL40Connection;
{$EndIf}
{$EndIf}
{$endif}
{$endif}
{$ENDIF}
end;
class function TMySQLConnectionDef.Description: String;
@ -1264,6 +1283,12 @@ begin
Result:=MysqlLoadedLibrary;
end;
{$IFDEF mysql56}
initialization
RegisterConnection(TMySQL56ConnectionDef);
finalization
UnRegisterConnection(TMySQL56ConnectionDef);
{$ELSE}
{$IfDef mysql55}
initialization
RegisterConnection(TMySQL55ConnectionDef);
@ -1288,20 +1313,14 @@ end;
finalization
UnRegisterConnection(TMySQL41ConnectionDef);
{$ELSE}
{$IFDEF mysql4} // temporary backwards compatibility for Lazarus
initialization
RegisterConnection(TMySQL40ConnectionDef);
finalization
UnRegisterConnection(TMySQL40ConnectionDef);
{$ELSE}
initialization
RegisterConnection(TMySQL40ConnectionDef);
finalization
UnRegisterConnection(TMySQL40ConnectionDef);
{$EndIf}
initialization
RegisterConnection(TMySQL40ConnectionDef);
finalization
UnRegisterConnection(TMySQL40ConnectionDef);
{$EndIf}
{$EndIf}
{$ENDIF}
{$endif}
{$ENDIF}
end.

View File

@ -7,7 +7,7 @@ interface
uses
Classes, SysUtils, toolsunit
,db, sqldb
,mysql40conn, mysql41conn, mysql50conn, mysql51conn, mysql55conn
,mysql40conn, mysql41conn, mysql50conn, mysql51conn, mysql55conn, mysql56conn
,ibconnection
,pqconnection
,odbcconn
@ -20,13 +20,13 @@ uses
;
type
TSQLConnType = (mysql40,mysql41,mysql50,mysql51,mysql55,postgresql,interbase,odbc,oracle,sqlite3,mssql,sybase);
TSQLConnType = (mysql40,mysql41,mysql50,mysql51,mysql55,mysql56,postgresql,interbase,odbc,oracle,sqlite3,mssql,sybase);
TSQLServerType = (ssFirebird, ssInterbase, ssMSSQL, ssMySQL, ssOracle, ssPostgreSQL, ssSQLite, ssSybase, ssUnknown);
const
MySQLConnTypes = [mysql40,mysql41,mysql50,mysql51,mysql55];
MySQLConnTypes = [mysql40,mysql41,mysql50,mysql51,mysql55,mysql56];
SQLConnTypesNames : Array [TSQLConnType] of String[19] =
('MYSQL40','MYSQL41','MYSQL50','MYSQL51','MYSQL55','POSTGRESQL','INTERBASE','ODBC','ORACLE','SQLITE3','MSSQL','SYBASE');
('MYSQL40','MYSQL41','MYSQL50','MYSQL51','MYSQL55','MYSQL56','POSTGRESQL','INTERBASE','ODBC','ORACLE','SQLITE3','MSSQL','SYBASE');
STestNotApplicable = 'This test does not apply to this sqldb-connection type';
@ -135,7 +135,7 @@ const
// fall back mapping (e.g. in case GetConnectionInfo(citServerType) is not implemented)
SQLConnTypeToServerTypeMap : array[TSQLConnType] of TSQLServerType =
(ssMySQL,ssMySQL,ssMySQL,ssMySQL,ssMySQL,ssPostgreSQL,ssFirebird,ssUnknown,ssOracle,ssSQLite,ssMSSQL,ssSybase);
(ssMySQL,ssMySQL,ssMySQL,ssMySQL,ssMySQL,ssMySQL,ssPostgreSQL,ssFirebird,ssUnknown,ssOracle,ssSQLite,ssMSSQL,ssSybase);
{ TSQLDBConnector }
@ -153,6 +153,7 @@ begin
if SQLConnType = MYSQL50 then Fconnection := TMySQL50Connection.Create(nil);
if SQLConnType = MYSQL51 then Fconnection := TMySQL51Connection.Create(nil);
if SQLConnType = MYSQL55 then Fconnection := TMySQL55Connection.Create(nil);
if SQLConnType = MYSQL56 then Fconnection := TMySQL56Connection.Create(nil);
if SQLConnType = SQLITE3 then Fconnection := TSQLite3Connection.Create(nil);
if SQLConnType = POSTGRESQL then Fconnection := TPQConnection.Create(nil);
if SQLConnType = INTERBASE then Fconnection := TIBConnection.Create(nil);
@ -228,8 +229,9 @@ begin
end;
ssMySQL:
begin
// Add into my.ini: sql-mode="...,PAD_CHAR_TO_FULL_LENGTH,ANSI_QUOTES"
FieldtypeDefinitions[ftWord] := 'SMALLINT UNSIGNED';
//MySQL recognizes BOOLEAN, but as synonym for TINYINT, not true sql boolean datatype
// MySQL recognizes BOOLEAN, but as synonym for TINYINT, not true sql boolean datatype
FieldtypeDefinitions[ftBoolean] := '';
// Use 'DATETIME' for datetime-fields instead of timestamp, because
// mysql's timestamps are only valid in the range 1970-2038.

View File

@ -2093,8 +2093,8 @@ begin
AFldName:=Adataset.Fields[1];
for i := 1 to 5 do
begin
AssertEquals(i,AFldID.asinteger);
AssertEquals('TestName'+inttostr(i),AFldName.asstring);
AssertEquals(i, AFldID.AsInteger);
AssertEquals('TestName'+inttostr(i), AFldName.AsString);
ADataset.Next;
end;
@ -2107,11 +2107,11 @@ begin
ADataset.First;
for i := 1 to 5 do
begin
AssertEquals(i,AFldID.AsInteger);
AssertEquals('ID', i, AFldID.AsInteger);
if i = 2 then
AssertEquals('test',AFldName.AsString)
AssertEquals('NAME', 'test', AFldName.AsString)
else
AssertEquals('TestName'+inttostr(i),AFldName.AsString);
AssertEquals('NAME', 'TestName'+inttostr(i), AFldName.AsString);
ADataset.Next;
end;
ADataset.Next;