fcl-db: mysql: add MySQL57Connection. Requires rev.31218.

(Tested with MySQL Server 5.7.7 RC)

git-svn-id: trunk@31220 -
This commit is contained in:
lacak 2015-07-23 10:27:29 +00:00
parent 40eec2f249
commit 61c451b391
3 changed files with 72 additions and 25 deletions

View File

@ -6,8 +6,9 @@
main=fcl-db main=fcl-db
[target] [target]
units=mysql40conn mysql41conn mysql50conn mysql51conn mysql55conn mysql56conn units=mysql40conn mysql41conn mysql50conn mysql51conn mysql55conn mysql56conn mysql57conn
rsts=mysql40conn mysql41conn mysql50conn mysql51conn mysql55conn mysql56conn rsts=mysql40conn mysql41conn mysql50conn mysql51conn mysql55conn mysql56conn mysql57conn
[require] [require]
packages=fcl-xml mysql packages=fcl-xml mysql

View File

@ -1,3 +1,6 @@
{$IFDEF MYSQL57_UP}
{$DEFINE MYSQL56_UP}
{$ENDIF}
{$IFDEF MYSQL56_UP} {$IFDEF MYSQL56_UP}
{$DEFINE MYSQL55_UP} {$DEFINE MYSQL55_UP}
{$ENDIF} {$ENDIF}
@ -14,6 +17,9 @@ interface
uses uses
Classes, SysUtils,bufdataset,sqldb,db,ctypes, Classes, SysUtils,bufdataset,sqldb,db,ctypes,
{$IFDEF mysql57}
mysql57dyn;
{$ELSE}
{$IFDEF mysql56} {$IFDEF mysql56}
mysql56dyn; mysql56dyn;
{$ELSE} {$ELSE}
@ -35,9 +41,13 @@ uses
{$endif} {$endif}
{$endif} {$endif}
{$ENDIF} {$ENDIF}
{$ENDIF}
Const Const
MySQLVersion = MySQLVersion =
{$IFDEF mysql57}
'5.7';
{$ELSE}
{$IFDEF mysql56} {$IFDEF mysql56}
'5.6'; '5.6';
{$ELSE} {$ELSE}
@ -59,11 +69,17 @@ Const
{$endif} {$endif}
{$endif} {$endif}
{$ENDIF} {$ENDIF}
{$ENDIF}
MariaDBVersion = MariaDBVersion =
{$IFDEF mysql57}
'10.1';
{$ELSE}
{$IFDEF mysql56} // MariaDB 10.0 is compatible with MySQL 5.6 {$IFDEF mysql56} // MariaDB 10.0 is compatible with MySQL 5.6
'10.0'; '10.0';
{$ELSE} // MariaDB 5.1..5.5 presumably report the same version number as MySQL {$ELSE} // MariaDB 5.1..5.5 presumably report the same version number as MySQL
MySQLVersion; MySQLVersion;
{$ENDIF}
{$ENDIF} {$ENDIF}
Type Type
@ -170,6 +186,12 @@ Type
end; end;
{$IFDEF mysql57}
TMySQL57Connection = Class(TConnectionName);
TMySQL57ConnectionDef = Class(TMySQLConnectionDef);
TMySQL57Transaction = Class(TTransactionName);
TMySQL57Cursor = Class(TCursorName);
{$ELSE}
{$IFDEF mysql56} {$IFDEF mysql56}
TMySQL56Connection = Class(TConnectionName); TMySQL56Connection = Class(TConnectionName);
TMySQL56ConnectionDef = Class(TMySQLConnectionDef); TMySQL56ConnectionDef = Class(TMySQLConnectionDef);
@ -209,6 +231,7 @@ Type
{$EndIf} {$EndIf}
{$ENDIF} {$ENDIF}
{$ENDIF} {$ENDIF}
{$ENDIF}
implementation implementation
@ -242,6 +265,9 @@ const
,'MYSQL_SERVER_PUBLIC_KEY' ,'MYSQL_SERVER_PUBLIC_KEY'
,'MYSQL_ENABLE_CLEARTEXT_PLUGIN' ,'MYSQL_ENABLE_CLEARTEXT_PLUGIN'
,'MYSQL_OPT_CAN_HANDLE_EXPIRED_PASSWORDS' ,'MYSQL_OPT_CAN_HANDLE_EXPIRED_PASSWORDS'
{$IFDEF MYSQL57_UP}
,'MYSQL_OPT_SSL_ENFORCE'
{$ENDIF}
{$ENDIF} {$ENDIF}
{$ENDIF} {$ENDIF}
{$ENDIF} {$ENDIF}
@ -470,12 +496,12 @@ var
FullVersion: string; FullVersion: string;
begin begin
InitialiseMysql; InitialiseMysql;
Fullversion:=strpas(mysql_get_client_info()); FullVersion:=strpas(mysql_get_client_info());
// Version string should start with version number: // Version string should start with version number:
// Note: in case of MariaDB version mismatch: tough luck, we report MySQL // Note: in case of MariaDB version mismatch: tough luck, we report MySQL
// version only. // version only.
if (pos(MySQLVersion, Fullversion) <> 1) and if (pos(MySQLVersion, FullVersion) <> 1) and
(pos(MariaDBVersion, Fullversion) <> 1) then (pos(MariaDBVersion, FullVersion) <> 1) then
Raise EInOutError.CreateFmt(SErrVersionMisMatch,[ClassName,MySQLVersion,FullVersion]); Raise EInOutError.CreateFmt(SErrVersionMisMatch,[ClassName,MySQLVersion,FullVersion]);
inherited DoInternalConnect; inherited DoInternalConnect;
ConnectToServer; ConnectToServer;
@ -497,6 +523,9 @@ end;
Function TConnectionName.AllocateCursorHandle: TSQLCursor; Function TConnectionName.AllocateCursorHandle: TSQLCursor;
begin begin
{$IFDEF mysql57}
Result:=TMySQL57Cursor.Create;
{$ELSE}
{$IFDEF mysql56} {$IFDEF mysql56}
Result:=TMySQL56Cursor.Create; Result:=TMySQL56Cursor.Create;
{$ELSE} {$ELSE}
@ -518,6 +547,7 @@ begin
{$EndIf} {$EndIf}
{$EndIf} {$EndIf}
{$ENDIF} {$ENDIF}
{$ENDIF}
end; end;
Procedure TConnectionName.DeAllocateCursorHandle(var cursor : TSQLCursor); Procedure TConnectionName.DeAllocateCursorHandle(var cursor : TSQLCursor);
@ -599,12 +629,14 @@ begin
// paramreplacestring kan een probleem geven bij postgres als hij niet meer gewoon $ is? // paramreplacestring kan een probleem geven bij postgres als hij niet meer gewoon $ is?
C.FStatement := stringsreplace(C.FStatement,ParamNames,ParamValues,[rfReplaceAll]); C.FStatement := stringsreplace(C.FStatement,ParamNames,ParamValues,[rfReplaceAll]);
end; end;
if LogEvent(detParamValue) then if LogEvent(detParamValue) then
LogParams(AParams); LogParams(AParams);
if LogEvent(detExecute) then if LogEvent(detExecute) then
Log(detExecute, C.FStatement); Log(detExecute, C.FStatement);
if LogEvent(detActualSQL) then if LogEvent(detActualSQL) then
Log(detActualSQL,C.FStatement); Log(detActualSQL,C.FStatement);
if mysql_query(FMySQL,Pchar(C.FStatement))<>0 then if mysql_query(FMySQL,Pchar(C.FStatement))<>0 then
begin begin
if not ForcedClose then if not ForcedClose then
@ -1274,6 +1306,9 @@ end;
class function TMySQLConnectionDef.ConnectionClass: TSQLConnectionClass; class function TMySQLConnectionDef.ConnectionClass: TSQLConnectionClass;
begin begin
{$IFDEF mysql57}
Result:=TMySQL57Connection;
{$ELSE}
{$IFDEF mysql56} {$IFDEF mysql56}
Result:=TMySQL56Connection; Result:=TMySQL56Connection;
{$ELSE} {$ELSE}
@ -1295,11 +1330,12 @@ begin
{$endif} {$endif}
{$endif} {$endif}
{$ENDIF} {$ENDIF}
{$ENDIF}
end; end;
class function TMySQLConnectionDef.Description: String; class function TMySQLConnectionDef.Description: String;
begin begin
Result:='Connect to a MySQL '+MySQLVersion+'database directly via the client library'; Result:='Connect to a MySQL '+MySQLVersion+' database directly via the client library';
end; end;
class function TMySQLConnectionDef.DefaultLibraryName: String; class function TMySQLConnectionDef.DefaultLibraryName: String;
@ -1322,6 +1358,12 @@ begin
Result:=MysqlLoadedLibrary; Result:=MysqlLoadedLibrary;
end; end;
{$IFDEF mysql57}
initialization
RegisterConnection(TMySQL57ConnectionDef);
finalization
UnRegisterConnection(TMySQL57ConnectionDef);
{$ELSE}
{$IFDEF mysql56} {$IFDEF mysql56}
initialization initialization
RegisterConnection(TMySQL56ConnectionDef); RegisterConnection(TMySQL56ConnectionDef);
@ -1361,5 +1403,6 @@ end;
{$ENDIF} {$ENDIF}
{$endif} {$endif}
{$ENDIF} {$ENDIF}
{$ENDIF}
end. end.

View File

@ -7,7 +7,7 @@ interface
uses uses
Classes, SysUtils, toolsunit Classes, SysUtils, toolsunit
,db, sqldb ,db, sqldb
,mysql40conn, mysql41conn, mysql50conn, mysql51conn, mysql55conn, mysql56conn ,mysql40conn, mysql41conn, mysql50conn, mysql51conn, mysql55conn, mysql56conn, mysql57conn
,ibconnection ,ibconnection
,pqconnection ,pqconnection
,odbcconn ,odbcconn
@ -20,13 +20,13 @@ uses
; ;
type type
TSQLConnType = (mysql40,mysql41,mysql50,mysql51,mysql55,mysql56,postgresql,interbase,odbc,oracle,sqlite3,mssql,sybase); TSQLConnType = (mysql40,mysql41,mysql50,mysql51,mysql55,mysql56,mysql57,postgresql,interbase,odbc,oracle,sqlite3,mssql,sybase);
TSQLServerType = (ssFirebird, ssInterbase, ssMSSQL, ssMySQL, ssOracle, ssPostgreSQL, ssSQLite, ssSybase, ssUnknown); TSQLServerType = (ssFirebird, ssInterbase, ssMSSQL, ssMySQL, ssOracle, ssPostgreSQL, ssSQLite, ssSybase, ssUnknown);
const const
MySQLConnTypes = [mysql40,mysql41,mysql50,mysql51,mysql55,mysql56]; MySQLConnTypes = [mysql40,mysql41,mysql50,mysql51,mysql55,mysql56,mysql57];
SQLConnTypesNames : Array [TSQLConnType] of String[19] = SQLConnTypesNames : Array [TSQLConnType] of String[19] =
('MYSQL40','MYSQL41','MYSQL50','MYSQL51','MYSQL55','MYSQL56','POSTGRESQL','INTERBASE','ODBC','ORACLE','SQLITE3','MSSQL','SYBASE'); ('MYSQL40','MYSQL41','MYSQL50','MYSQL51','MYSQL55','MYSQL56','MYSQL57','POSTGRESQL','INTERBASE','ODBC','ORACLE','SQLITE3','MSSQL','SYBASE');
STestNotApplicable = 'This test does not apply to this sqldb connection type'; STestNotApplicable = 'This test does not apply to this sqldb connection type';
@ -142,7 +142,7 @@ const
// fall back mapping (e.g. in case GetConnectionInfo(citServerType) is not implemented) // fall back mapping (e.g. in case GetConnectionInfo(citServerType) is not implemented)
SQLConnTypeToServerTypeMap : array[TSQLConnType] of TSQLServerType = SQLConnTypeToServerTypeMap : array[TSQLConnType] of TSQLServerType =
(ssMySQL,ssMySQL,ssMySQL,ssMySQL,ssMySQL,ssMySQL,ssPostgreSQL,ssFirebird,ssUnknown,ssOracle,ssSQLite,ssMSSQL,ssSybase); (ssMySQL,ssMySQL,ssMySQL,ssMySQL,ssMySQL,ssMySQL,ssMySQL,ssPostgreSQL,ssFirebird,ssUnknown,ssOracle,ssSQLite,ssMSSQL,ssSybase);
function IdentifierCase(const s: string): string; function IdentifierCase(const s: string): string;
@ -167,21 +167,24 @@ begin
for t := low(SQLConnTypesNames) to high(SQLConnTypesNames) do for t := low(SQLConnTypesNames) to high(SQLConnTypesNames) do
if UpperCase(dbconnectorparams) = SQLConnTypesNames[t] then SQLConnType := t; if UpperCase(dbconnectorparams) = SQLConnTypesNames[t] then SQLConnType := t;
if SQLConnType = MYSQL40 then Fconnection := TMySQL40Connection.Create(nil); case SQLConnType of
if SQLConnType = MYSQL41 then Fconnection := TMySQL41Connection.Create(nil); MYSQL40: Fconnection := TMySQL40Connection.Create(nil);
if SQLConnType = MYSQL50 then Fconnection := TMySQL50Connection.Create(nil); MYSQL41: Fconnection := TMySQL41Connection.Create(nil);
if SQLConnType = MYSQL51 then Fconnection := TMySQL51Connection.Create(nil); MYSQL50: Fconnection := TMySQL50Connection.Create(nil);
if SQLConnType = MYSQL55 then Fconnection := TMySQL55Connection.Create(nil); MYSQL51: Fconnection := TMySQL51Connection.Create(nil);
if SQLConnType = MYSQL56 then Fconnection := TMySQL56Connection.Create(nil); MYSQL55: Fconnection := TMySQL55Connection.Create(nil);
if SQLConnType = SQLITE3 then Fconnection := TSQLite3Connection.Create(nil); MYSQL56: Fconnection := TMySQL56Connection.Create(nil);
if SQLConnType = POSTGRESQL then Fconnection := TPQConnection.Create(nil); MYSQL57: Fconnection := TMySQL57Connection.Create(nil);
if SQLConnType = INTERBASE then Fconnection := TIBConnection.Create(nil); SQLITE3: Fconnection := TSQLite3Connection.Create(nil);
if SQLConnType = ODBC then Fconnection := TODBCConnection.Create(nil); POSTGRESQL: Fconnection := TPQConnection.Create(nil);
INTERBASE : Fconnection := TIBConnection.Create(nil);
ODBC: Fconnection := TODBCConnection.Create(nil);
{$IFNDEF Win64} {$IFNDEF Win64}
if SQLConnType = ORACLE then Fconnection := TOracleConnection.Create(nil); ORACLE: Fconnection := TOracleConnection.Create(nil);
{$ENDIF Win64} {$ENDIF Win64}
if SQLConnType = MSSQL then Fconnection := TMSSQLConnection.Create(nil); MSSQL: Fconnection := TMSSQLConnection.Create(nil);
if SQLConnType = SYBASE then Fconnection := TSybaseConnection.Create(nil); SYBASE: Fconnection := TSybaseConnection.Create(nil);
end;
if not assigned(Fconnection) then writeln('Invalid database type, check if a valid database type for your achitecture was provided in the file ''database.ini'''); if not assigned(Fconnection) then writeln('Invalid database type, check if a valid database type for your achitecture was provided in the file ''database.ini''');