mysqlconn.inc 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  1. {$mode objfpc}{$H+}
  2. {$MACRO on}
  3. interface
  4. uses
  5. Classes, SysUtils,sqldb,db,dynlibs,
  6. {$IfDef mysql50}
  7. mysql50dyn;
  8. {$DEFINE TConnectionName:=TMySQL50Connection}
  9. {$DEFINE TTransactionName:=TMySQL50Transaction}
  10. {$DEFINE TCursorName:=TMySQL50Cursor}
  11. {$ELSE}
  12. {$IfDef mysql41}
  13. mysql41dyn;
  14. {$DEFINE TConnectionName:=TMySQL41Connection}
  15. {$DEFINE TTransactionName:=TMySQL41Transaction}
  16. {$DEFINE TCursorName:=TMySQL41Cursor}
  17. {$ELSE}
  18. {$IFDEF mysql4} // temporary backwards compatibility for Lazarus
  19. mysql40dyn;
  20. {$DEFINE TConnectionName:=TMySQLConnection}
  21. {$DEFINE TTransactionName:=TMySQLTransaction}
  22. {$DEFINE TCursorName:=TMySQLCursor}
  23. {$ELSE}
  24. mysql40dyn;
  25. {$DEFINE TConnectionName:=TMySQL40Connection}
  26. {$DEFINE TTransactionName:=TMySQL40Transaction}
  27. {$DEFINE TCursorName:=TMySQL40Cursor}
  28. {$EndIf}
  29. {$EndIf}
  30. {$EndIf}
  31. Type
  32. TTransactionName = Class(TSQLHandle)
  33. protected
  34. end;
  35. TCursorName = Class(TSQLCursor)
  36. protected
  37. FQMySQL : PMySQL;
  38. FRes: PMYSQL_RES; { Record pointer }
  39. FNeedData : Boolean;
  40. FStatement : String;
  41. Row : MYSQL_ROW;
  42. RowsAffected : QWord;
  43. LastInsertID : QWord;
  44. ParamBinding : TParamBinding;
  45. ParamReplaceString : String;
  46. end;
  47. TConnectionName = class (TSQLConnection)
  48. private
  49. FDialect: integer;
  50. FHostInfo: String;
  51. FServerInfo: String;
  52. FMySQL : PMySQL;
  53. FDidConnect : Boolean;
  54. function GetClientInfo: string;
  55. function GetServerStatus: String;
  56. procedure ConnectMySQL(var HMySQL : PMySQL;H,U,P : pchar);
  57. protected
  58. function StrToStatementType(s : string) : TStatementType; override;
  59. Procedure ConnectToServer; virtual;
  60. Procedure SelectDatabase; virtual;
  61. function MySQLDataType(AType: enum_field_types; ASize: Integer; var NewType: TFieldType; var NewSize: Integer): Boolean;
  62. function MySQLWriteData(AType: enum_field_types; ASize: Integer; Source, Dest: PChar): Boolean;
  63. // SQLConnection methods
  64. procedure DoInternalConnect; override;
  65. procedure DoInternalDisconnect; override;
  66. function GetHandle : pointer; override;
  67. Function AllocateCursorHandle : TSQLCursor; override;
  68. Procedure DeAllocateCursorHandle(var cursor : TSQLCursor); override;
  69. Function AllocateTransactionHandle : TSQLHandle; override;
  70. procedure PrepareStatement(cursor: TSQLCursor;ATransaction : TSQLTransaction;buf : string; AParams : TParams); override;
  71. procedure UnPrepareStatement(cursor:TSQLCursor); override;
  72. procedure FreeFldBuffers(cursor : TSQLCursor); override;
  73. procedure Execute(cursor: TSQLCursor;atransaction:tSQLtransaction;AParams : TParams); override;
  74. procedure AddFieldDefs(cursor: TSQLCursor; FieldDefs : TfieldDefs); override;
  75. function Fetch(cursor : TSQLCursor) : boolean; override;
  76. function LoadField(cursor : TSQLCursor;FieldDef : TfieldDef;buffer : pointer) : boolean; override;
  77. function GetTransactionHandle(trans : TSQLHandle): pointer; override;
  78. function Commit(trans : TSQLHandle) : boolean; override;
  79. function RollBack(trans : TSQLHandle) : boolean; override;
  80. function StartdbTransaction(trans : TSQLHandle; AParams : string) : boolean; override;
  81. procedure CommitRetaining(trans : TSQLHandle); override;
  82. procedure RollBackRetaining(trans : TSQLHandle); override;
  83. procedure UpdateIndexDefs(var IndexDefs : TIndexDefs;TableName : string); override;
  84. Public
  85. Property ServerInfo : String Read FServerInfo;
  86. Property HostInfo : String Read FHostInfo;
  87. property ClientInfo: string read GetClientInfo;
  88. property ServerStatus : String read GetServerStatus;
  89. published
  90. property Dialect : integer read FDialect write FDialect;
  91. property DatabaseName;
  92. property HostName;
  93. property KeepConnection;
  94. property LoginPrompt;
  95. property Params;
  96. property OnLogin;
  97. end;
  98. EMySQLError = Class(Exception);
  99. implementation
  100. uses dbconst;
  101. { TConnectionName }
  102. Resourcestring
  103. SErrServerConnectFailed = 'Server connect failed.';
  104. SErrDatabaseSelectFailed = 'failed to select database: %s';
  105. SErrDatabaseCreate = 'Failed to create database: %s';
  106. SErrDatabaseDrop = 'Failed to drop database: %s';
  107. SErrNoData = 'No data for record';
  108. SErrExecuting = 'Error executing query: %s';
  109. SErrFetchingdata = 'Error fetching row data: %s';
  110. SErrGettingResult = 'Error getting result set: %s';
  111. SErrNoQueryResult = 'No result from query.';
  112. SErrNotversion50 = 'TMySQL50Connection can not work with the installed MySQL client version (%s).';
  113. SErrNotversion41 = 'TMySQL41Connection can not work with the installed MySQL client version (%s).';
  114. SErrNotversion40 = 'TMySQL40Connection can not work with the installed MySQL client version (%s).';
  115. Procedure MySQlError(R : PMySQL;Msg: String;Comp : TComponent);
  116. Var
  117. MySQLMsg : String;
  118. begin
  119. If (R<>Nil) then
  120. begin
  121. MySQLMsg:=Strpas(mysql_error(R));
  122. DatabaseErrorFmt(Msg,[MySQLMsg],Comp);
  123. end
  124. else
  125. DatabaseError(Msg,Comp);
  126. end;
  127. function TConnectionName.StrToStatementType(s : string) : TStatementType;
  128. begin
  129. S:=Lowercase(s);
  130. if s = 'show' then exit(stSelect);
  131. result := inherited StrToStatementType(s);
  132. end;
  133. function TConnectionName.GetClientInfo: string;
  134. Var
  135. B : Boolean;
  136. begin
  137. // To make it possible to call this if there's no connection yet
  138. B:=(MysqlLibraryHandle=Nilhandle);
  139. If B then
  140. InitialiseMysql;
  141. Try
  142. Result:=strpas(mysql_get_client_info());
  143. Finally
  144. if B then
  145. ReleaseMysql;
  146. end;
  147. end;
  148. function TConnectionName.GetServerStatus: String;
  149. begin
  150. CheckConnected;
  151. Result := mysql_stat(FMYSQL);
  152. end;
  153. procedure TConnectionName.ConnectMySQL(var HMySQL : PMySQL;H,U,P : pchar);
  154. begin
  155. HMySQL := mysql_init(HMySQL);
  156. HMySQL:=mysql_real_connect(HMySQL,PChar(H),PChar(U),Pchar(P),Nil,0,Nil,0);
  157. If (HMySQL=Nil) then
  158. MySQlError(Nil,SErrServerConnectFailed,Self);
  159. end;
  160. procedure TConnectionName.ConnectToServer;
  161. Var
  162. H,U,P : String;
  163. begin
  164. H:=HostName;
  165. U:=UserName;
  166. P:=Password;
  167. ConnectMySQL(FMySQL,pchar(H),pchar(U),pchar(P));
  168. FServerInfo := strpas(mysql_get_server_info(FMYSQL));
  169. FHostInfo := strpas(mysql_get_host_info(FMYSQL));
  170. end;
  171. procedure TConnectionName.SelectDatabase;
  172. begin
  173. if mysql_select_db(FMySQL,pchar(DatabaseName))<>0 then
  174. MySQLError(FMySQL,SErrDatabaseSelectFailed,Self);
  175. end;
  176. procedure TConnectionName.DoInternalConnect;
  177. begin
  178. FDidConnect:=(MySQLLibraryHandle=NilHandle);
  179. if FDidConnect then
  180. InitialiseMysql;
  181. {$IFDEF mysql50}
  182. if copy(strpas(mysql_get_client_info()),1,3)<>'5.0' then
  183. Raise EInOutError.CreateFmt(SErrNotversion50,[strpas(mysql_get_client_info())]);
  184. {$ELSE}
  185. {$IFDEF mysql41}
  186. if copy(strpas(mysql_get_client_info()),1,3)<>'4.1' then
  187. Raise EInOutError.CreateFmt(SErrNotversion41,[strpas(mysql_get_client_info())]);
  188. {$ELSE}
  189. if copy(strpas(mysql_get_client_info()),1,3)<>'4.0' then
  190. Raise EInOutError.CreateFmt(SErrNotversion40,[strpas(mysql_get_client_info())]);
  191. {$ENDIF}
  192. {$ENDIF}
  193. inherited DoInternalConnect;
  194. ConnectToServer;
  195. SelectDatabase;
  196. end;
  197. procedure TConnectionName.DoInternalDisconnect;
  198. begin
  199. inherited DoInternalDisconnect;
  200. mysql_close(FMySQL);
  201. FMySQL:=Nil;
  202. if FDidConnect then
  203. ReleaseMysql;
  204. end;
  205. function TConnectionName.GetHandle: pointer;
  206. begin
  207. Result:=FMySQL;
  208. end;
  209. function TConnectionName.AllocateCursorHandle: TSQLCursor;
  210. begin
  211. Result:=TCursorName.Create;
  212. end;
  213. Procedure TConnectionName.DeAllocateCursorHandle(var cursor : TSQLCursor);
  214. begin
  215. FreeAndNil(cursor);
  216. end;
  217. function TConnectionName.AllocateTransactionHandle: TSQLHandle;
  218. begin
  219. // Result:=TTransactionName.Create;
  220. Result := nil;
  221. end;
  222. procedure TConnectionName.PrepareStatement(cursor: TSQLCursor;
  223. ATransaction: TSQLTransaction; buf: string;AParams : TParams);
  224. begin
  225. // if assigned(AParams) and (AParams.count > 0) then
  226. // DatabaseError('Parameters (not) yet supported for the MySQL SqlDB connection.',self);
  227. With Cursor as TCursorName do
  228. begin
  229. FStatement:=Buf;
  230. if assigned(AParams) and (AParams.count > 0) then
  231. FStatement := AParams.ParseSQL(FStatement,false,psSimulated,paramBinding,ParamReplaceString);
  232. if FStatementType=stSelect then
  233. FNeedData:=True;
  234. ConnectMySQL(FQMySQL,FMySQL^.host,FMySQL^.user,FMySQL^.passwd);
  235. if mysql_select_db(FQMySQL,pchar(DatabaseName))<>0 then
  236. MySQLError(FQMySQL,SErrDatabaseSelectFailed,Self);
  237. end
  238. end;
  239. procedure TConnectionName.UnPrepareStatement(cursor: TSQLCursor);
  240. begin
  241. With Cursor as TCursorName do
  242. begin
  243. mysql_close(FQMySQL);
  244. FQMysql := nil;
  245. end;
  246. end;
  247. procedure TConnectionName.FreeFldBuffers(cursor: TSQLCursor);
  248. Var
  249. C : TCursorName;
  250. begin
  251. C:=Cursor as TCursorName;
  252. if c.FStatementType=stSelect then
  253. c.FNeedData:=False;
  254. if (c.FQMySQL <> Nil) then
  255. begin
  256. mysql_close(c.FQMySQL);
  257. c.FQMySQL:=Nil;
  258. end;
  259. If (C.FRes<>Nil) then
  260. begin
  261. Mysql_free_result(C.FRes);
  262. C.FRes:=Nil;
  263. end;
  264. end;
  265. procedure TConnectionName.Execute(cursor: TSQLCursor;
  266. atransaction: tSQLtransaction;AParams : TParams);
  267. Var
  268. C : TCursorName;
  269. i : integer;
  270. begin
  271. C:=Cursor as TCursorName;
  272. If (C.FRes=Nil) then
  273. begin
  274. if Assigned(AParams) and (AParams.count > 0) then
  275. for i := 0 to AParams.count -1 do
  276. C.FStatement := stringreplace(C.FStatement,C.ParamReplaceString+inttostr(AParams[i].Index+1),GetAsSQLText(AParams[i]),[rfReplaceAll,rfIgnoreCase]);
  277. if mysql_query(c.FQMySQL,Pchar(C.FStatement))<>0 then
  278. MySQLError(c.FQMYSQL,Format(SErrExecuting,[StrPas(mysql_error(c.FQMySQL))]),Self)
  279. else
  280. begin
  281. C.RowsAffected := mysql_affected_rows(c.FQMYSQL);
  282. C.LastInsertID := mysql_insert_id(c.FQMYSQL);
  283. if C.FNeedData then
  284. C.FRes:=mysql_use_result(c.FQMySQL);
  285. end;
  286. end;
  287. end;
  288. function TConnectionName.MySQLDataType(AType: enum_field_types; ASize: Integer;
  289. var NewType: TFieldType; var NewSize: Integer): Boolean;
  290. begin
  291. Result := True;
  292. case AType of
  293. FIELD_TYPE_TINY, FIELD_TYPE_SHORT, FIELD_TYPE_LONG, FIELD_TYPE_LONGLONG,
  294. FIELD_TYPE_INT24:
  295. begin
  296. NewType := ftInteger;
  297. NewSize := 0;
  298. end;
  299. {$ifdef mysql50}
  300. FIELD_TYPE_NEWDECIMAL,
  301. {$endif}
  302. FIELD_TYPE_DECIMAL, FIELD_TYPE_FLOAT, FIELD_TYPE_DOUBLE:
  303. begin
  304. NewType := ftFloat;
  305. NewSize := 0;
  306. end;
  307. FIELD_TYPE_TIMESTAMP, FIELD_TYPE_DATETIME:
  308. begin
  309. NewType := ftDateTime;
  310. NewSize := 0;
  311. end;
  312. FIELD_TYPE_DATE:
  313. begin
  314. NewType := ftDate;
  315. NewSize := 0;
  316. end;
  317. FIELD_TYPE_TIME:
  318. begin
  319. NewType := ftTime;
  320. NewSize := 0;
  321. end;
  322. FIELD_TYPE_VAR_STRING, FIELD_TYPE_STRING, FIELD_TYPE_ENUM, FIELD_TYPE_SET:
  323. begin
  324. NewType := ftString;
  325. NewSize := ASize;
  326. end;
  327. else
  328. Result := False;
  329. end;
  330. end;
  331. procedure TConnectionName.AddFieldDefs(cursor: TSQLCursor;
  332. FieldDefs: TfieldDefs);
  333. var
  334. C : TCursorName;
  335. I, FC: Integer;
  336. field: PMYSQL_FIELD;
  337. DFT: TFieldType;
  338. DFS: Integer;
  339. begin
  340. // Writeln('MySQL: Adding fielddefs');
  341. C:=(Cursor as TCursorName);
  342. If (C.FRes=Nil) then
  343. begin
  344. // Writeln('res is nil');
  345. MySQLError(c.FQMySQL,SErrNoQueryResult,Self);
  346. end;
  347. // Writeln('MySQL: have result');
  348. FC:=mysql_num_fields(C.FRes);
  349. For I:= 0 to FC-1 do
  350. begin
  351. field := mysql_fetch_field_direct(C.FRES, I);
  352. // Writeln('MySQL: creating fielddef ',I+1);
  353. if MySQLDataType(field^.ftype, field^.length, DFT, DFS) then
  354. TFieldDef.Create(FieldDefs, field^.name, DFT, DFS, False, I+1);
  355. end;
  356. // Writeln('MySQL: Finished adding fielddefs');
  357. end;
  358. function TConnectionName.Fetch(cursor: TSQLCursor): boolean;
  359. Var
  360. C : TCursorName;
  361. begin
  362. C:=Cursor as TCursorName;
  363. C.Row:=MySQL_Fetch_row(C.FRes);
  364. Result:=(C.Row<>Nil);
  365. end;
  366. function TConnectionName.LoadField(cursor : TSQLCursor;
  367. FieldDef : TfieldDef;buffer : pointer) : boolean;
  368. var
  369. I, FC: Integer;
  370. field: PMYSQL_FIELD;
  371. row : MYSQL_ROW;
  372. C : TCursorName;
  373. begin
  374. // Writeln('LoadFieldsFromBuffer');
  375. C:=Cursor as TCursorName;
  376. if C.Row=nil then
  377. begin
  378. // Writeln('LoadFieldsFromBuffer: row=nil');
  379. MySQLError(c.FQMySQL,SErrFetchingData,Self);
  380. end;
  381. Row:=C.Row;
  382. FC := mysql_num_fields(C.FRES);
  383. for I := 0 to FC-1 do
  384. begin
  385. field := mysql_fetch_field_direct(C.FRES, I);
  386. if field^.name=FieldDef.name then break;
  387. Inc(Row);
  388. end;
  389. Result := MySQLWriteData(field^.ftype, field^.length, Row^, Buffer);
  390. end;
  391. function InternalStrToFloat(S: string): Extended;
  392. var
  393. I: Integer;
  394. Tmp: string;
  395. begin
  396. Tmp := '';
  397. for I := 1 to Length(S) do
  398. begin
  399. if not (S[I] in ['0'..'9', '+', '-', 'E', 'e']) then
  400. Tmp := Tmp + DecimalSeparator
  401. else
  402. Tmp := Tmp + S[I];
  403. end;
  404. Result := StrToFloat(Tmp);
  405. end;
  406. function InternalStrToDate(S: string): TDateTime;
  407. var
  408. EY, EM, ED: Word;
  409. begin
  410. EY := StrToInt(Copy(S,1,4));
  411. EM := StrToInt(Copy(S,6,2));
  412. ED := StrToInt(Copy(S,9,2));
  413. if (EY = 0) or (EM = 0) or (ED = 0) then
  414. Result:=0
  415. else
  416. Result:=EncodeDate(EY, EM, ED);
  417. end;
  418. function InternalStrToDateTime(S: string): TDateTime;
  419. var
  420. EY, EM, ED: Word;
  421. EH, EN, ES: Word;
  422. begin
  423. EY := StrToInt(Copy(S, 1, 4));
  424. EM := StrToInt(Copy(S, 6, 2));
  425. ED := StrToInt(Copy(S, 9, 2));
  426. EH := StrToInt(Copy(S, 12, 2));
  427. EN := StrToInt(Copy(S, 15, 2));
  428. ES := StrToInt(Copy(S, 18, 2));
  429. if (EY = 0) or (EM = 0) or (ED = 0) then
  430. Result := 0
  431. else
  432. Result := EncodeDate(EY, EM, ED);
  433. Result := Result + EncodeTime(EH, EN, ES, 0);
  434. end;
  435. function InternalStrToTime(S: string): TDateTime;
  436. var
  437. EH, EM, ES: Word;
  438. begin
  439. EH := StrToInt(Copy(S, 1, 2));
  440. EM := StrToInt(Copy(S, 4, 2));
  441. ES := StrToInt(Copy(S, 7, 2));
  442. Result := EncodeTime(EH, EM, ES, 0);
  443. end;
  444. function InternalStrToTimeStamp(S: string): TDateTime;
  445. var
  446. EY, EM, ED: Word;
  447. EH, EN, ES: Word;
  448. begin
  449. {$IFNDEF mysql40}
  450. EY := StrToInt(Copy(S, 1, 4));
  451. EM := StrToInt(Copy(S, 6, 2));
  452. ED := StrToInt(Copy(S, 9, 2));
  453. EH := StrToInt(Copy(S, 12, 2));
  454. EN := StrToInt(Copy(S, 15, 2));
  455. ES := StrToInt(Copy(S, 18, 2));
  456. {$ELSE}
  457. EY := StrToInt(Copy(S, 1, 4));
  458. EM := StrToInt(Copy(S, 5, 2));
  459. ED := StrToInt(Copy(S, 7, 2));
  460. EH := StrToInt(Copy(S, 9, 2));
  461. EN := StrToInt(Copy(S, 11, 2));
  462. ES := StrToInt(Copy(S, 13, 2));
  463. {$ENDIF}
  464. if (EY = 0) or (EM = 0) or (ED = 0) then
  465. Result := 0
  466. else
  467. Result := EncodeDate(EY, EM, ED);
  468. Result := Result + EncodeTime(EH, EN, ES, 0);;
  469. end;
  470. function TConnectionName.MySQLWriteData(AType: enum_field_types;ASize: Integer; Source, Dest: PChar): Boolean;
  471. var
  472. VI: Integer;
  473. VF: Double;
  474. VD: TDateTime;
  475. Src : String;
  476. begin
  477. Result := False;
  478. if Source = Nil then
  479. exit;
  480. Src:=StrPas(Source);
  481. case AType of
  482. FIELD_TYPE_TINY, FIELD_TYPE_SHORT, FIELD_TYPE_LONG, FIELD_TYPE_LONGLONG,
  483. FIELD_TYPE_INT24:
  484. begin
  485. if (Src<>'') then
  486. VI := StrToInt(Src)
  487. else
  488. VI := 0;
  489. Move(VI, Dest^, SizeOf(Integer));
  490. end;
  491. {$ifdef mysql50}
  492. FIELD_TYPE_NEWDECIMAL,
  493. {$endif}
  494. FIELD_TYPE_DECIMAL, FIELD_TYPE_FLOAT, FIELD_TYPE_DOUBLE:
  495. begin
  496. if Src <> '' then
  497. VF := InternalStrToFloat(Src)
  498. else
  499. VF := 0;
  500. Move(VF, Dest^, SizeOf(Double));
  501. end;
  502. FIELD_TYPE_TIMESTAMP:
  503. begin
  504. if Src <> '' then
  505. VD := InternalStrToTimeStamp(Src)
  506. else
  507. VD := 0;
  508. Move(VD, Dest^, SizeOf(TDateTime));
  509. end;
  510. FIELD_TYPE_DATETIME:
  511. begin
  512. if Src <> '' then
  513. VD := InternalStrToDateTime(Src)
  514. else
  515. VD := 0;
  516. Move(VD, Dest^, SizeOf(TDateTime));
  517. end;
  518. FIELD_TYPE_DATE:
  519. begin
  520. if Src <> '' then
  521. VD := InternalStrToDate(Src)
  522. else
  523. VD := 0;
  524. Move(VD, Dest^, SizeOf(TDateTime));
  525. end;
  526. FIELD_TYPE_TIME:
  527. begin
  528. if Src <> '' then
  529. VD := InternalStrToTime(Src)
  530. else
  531. VD := 0;
  532. Move(VD, Dest^, SizeOf(TDateTime));
  533. end;
  534. FIELD_TYPE_VAR_STRING, FIELD_TYPE_STRING, FIELD_TYPE_ENUM, FIELD_TYPE_SET:
  535. begin
  536. { Write('Moving string of size ',asize,' : ');
  537. P:=Source;
  538. If (P<>nil) then
  539. While P[0]<>#0 do
  540. begin
  541. Write(p[0]);
  542. inc(p);
  543. end;
  544. Writeln;
  545. } if Src<> '' then
  546. Move(Source^, Dest^, ASize)
  547. else
  548. Dest^ := #0;
  549. end;
  550. end;
  551. Result := True;
  552. end;
  553. procedure TConnectionName.UpdateIndexDefs(var IndexDefs : TIndexDefs;TableName : string);
  554. var qry : TSQLQuery;
  555. begin
  556. if not assigned(Transaction) then
  557. DatabaseError(SErrConnTransactionnSet);
  558. qry := tsqlquery.Create(nil);
  559. qry.transaction := Transaction;
  560. qry.database := Self;
  561. with qry do
  562. begin
  563. ReadOnly := True;
  564. sql.clear;
  565. sql.add('show index from ' + TableName);
  566. open;
  567. end;
  568. while not qry.eof do with IndexDefs.AddIndexDef do
  569. begin
  570. Name := trim(qry.fieldbyname('Key_name').asstring);
  571. Fields := trim(qry.fieldbyname('Column_name').asstring);
  572. If Name = 'PRIMARY' then options := options + [ixPrimary];
  573. If qry.fieldbyname('Non_unique').asinteger = 0 then options := options + [ixUnique];
  574. qry.next;
  575. { while (name = qry.fields[0].asstring) and (not qry.eof) do
  576. begin
  577. Fields := Fields + ';' + trim(qry.Fields[2].asstring);
  578. qry.next;
  579. end;}
  580. end;
  581. qry.close;
  582. qry.free;
  583. end;
  584. function TConnectionName.GetTransactionHandle(trans: TSQLHandle): pointer;
  585. begin
  586. Result:=Nil;
  587. end;
  588. function TConnectionName.Commit(trans: TSQLHandle): boolean;
  589. begin
  590. // Do nothing.
  591. end;
  592. function TConnectionName.RollBack(trans: TSQLHandle): boolean;
  593. begin
  594. // Do nothing
  595. end;
  596. function TConnectionName.StartdbTransaction(trans: TSQLHandle; AParams : string): boolean;
  597. begin
  598. // Do nothing
  599. end;
  600. procedure TConnectionName.CommitRetaining(trans: TSQLHandle);
  601. begin
  602. // Do nothing
  603. end;
  604. procedure TConnectionName.RollBackRetaining(trans: TSQLHandle);
  605. begin
  606. // Do nothing
  607. end;
  608. end.