mysqlconn.inc 17 KB

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