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
[target]
units=mysql40conn mysql41conn mysql50conn mysql51conn mysql55conn mysql56conn
rsts=mysql40conn mysql41conn mysql50conn mysql51conn mysql55conn mysql56conn
units=mysql40conn mysql41conn mysql50conn mysql51conn mysql55conn mysql56conn mysql57conn
rsts=mysql40conn mysql41conn mysql50conn mysql51conn mysql55conn mysql56conn mysql57conn
[require]
packages=fcl-xml mysql

View File

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

View File

@ -7,7 +7,7 @@ interface
uses
Classes, SysUtils, toolsunit
,db, sqldb
,mysql40conn, mysql41conn, mysql50conn, mysql51conn, mysql55conn, mysql56conn
,mysql40conn, mysql41conn, mysql50conn, mysql51conn, mysql55conn, mysql56conn, mysql57conn
,ibconnection
,pqconnection
,odbcconn
@ -20,13 +20,13 @@ uses
;
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);
const
MySQLConnTypes = [mysql40,mysql41,mysql50,mysql51,mysql55,mysql56];
MySQLConnTypes = [mysql40,mysql41,mysql50,mysql51,mysql55,mysql56,mysql57];
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';
@ -142,7 +142,7 @@ const
// fall back mapping (e.g. in case GetConnectionInfo(citServerType) is not implemented)
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;
@ -167,21 +167,24 @@ begin
for t := low(SQLConnTypesNames) to high(SQLConnTypesNames) do
if UpperCase(dbconnectorparams) = SQLConnTypesNames[t] then SQLConnType := t;
if SQLConnType = MYSQL40 then Fconnection := TMySQL40Connection.Create(nil);
if SQLConnType = MYSQL41 then Fconnection := TMySQL41Connection.Create(nil);
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);
if SQLConnType = ODBC then Fconnection := TODBCConnection.Create(nil);
case SQLConnType of
MYSQL40: Fconnection := TMySQL40Connection.Create(nil);
MYSQL41: Fconnection := TMySQL41Connection.Create(nil);
MYSQL50: Fconnection := TMySQL50Connection.Create(nil);
MYSQL51: Fconnection := TMySQL51Connection.Create(nil);
MYSQL55: Fconnection := TMySQL55Connection.Create(nil);
MYSQL56: Fconnection := TMySQL56Connection.Create(nil);
MYSQL57: Fconnection := TMySQL57Connection.Create(nil);
SQLITE3: Fconnection := TSQLite3Connection.Create(nil);
POSTGRESQL: Fconnection := TPQConnection.Create(nil);
INTERBASE : Fconnection := TIBConnection.Create(nil);
ODBC: Fconnection := TODBCConnection.Create(nil);
{$IFNDEF Win64}
if SQLConnType = ORACLE then Fconnection := TOracleConnection.Create(nil);
ORACLE: Fconnection := TOracleConnection.Create(nil);
{$ENDIF Win64}
if SQLConnType = MSSQL then Fconnection := TMSSQLConnection.Create(nil);
if SQLConnType = SYBASE then Fconnection := TSybaseConnection.Create(nil);
MSSQL: Fconnection := TMSSQLConnection.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''');