mysqlconn.inc 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  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.FRes<>Nil) then
  251. begin
  252. C.FRes:=Nil;
  253. end;
  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. begin
  270. C:=Cursor as TCursorName;
  271. If (C.FRes=Nil) then
  272. begin
  273. if mysql_query(c.FQMySQL,Pchar(C.FStatement))<>0 then
  274. MySQLError(c.FQMYSQL,Format(SErrExecuting,[StrPas(mysql_error(c.FQMySQL))]),Self)
  275. else
  276. begin
  277. C.RowsAffected := mysql_affected_rows(c.FQMYSQL);
  278. C.LastInsertID := mysql_insert_id(c.FQMYSQL);
  279. if C.FNeedData then
  280. C.FRes:=mysql_use_result(c.FQMySQL);
  281. end;
  282. end;
  283. end;
  284. function TConnectionName.MySQLDataType(AType: enum_field_types; ASize: Integer;
  285. var NewType: TFieldType; var NewSize: Integer): Boolean;
  286. begin
  287. Result := True;
  288. case AType of
  289. FIELD_TYPE_TINY, FIELD_TYPE_SHORT, FIELD_TYPE_LONG, FIELD_TYPE_LONGLONG,
  290. FIELD_TYPE_INT24:
  291. begin
  292. NewType := ftInteger;
  293. NewSize := 0;
  294. end;
  295. FIELD_TYPE_DECIMAL, FIELD_TYPE_FLOAT, FIELD_TYPE_DOUBLE:
  296. begin
  297. NewType := ftFloat;
  298. NewSize := 0;
  299. end;
  300. FIELD_TYPE_TIMESTAMP, FIELD_TYPE_DATETIME:
  301. begin
  302. NewType := ftDateTime;
  303. NewSize := 0;
  304. end;
  305. FIELD_TYPE_DATE:
  306. begin
  307. NewType := ftDate;
  308. NewSize := 0;
  309. end;
  310. FIELD_TYPE_TIME:
  311. begin
  312. NewType := ftTime;
  313. NewSize := 0;
  314. end;
  315. FIELD_TYPE_VAR_STRING, FIELD_TYPE_STRING, FIELD_TYPE_ENUM, FIELD_TYPE_SET:
  316. begin
  317. NewType := ftString;
  318. NewSize := ASize;
  319. end;
  320. else
  321. Result := False;
  322. end;
  323. end;
  324. procedure TConnectionName.AddFieldDefs(cursor: TSQLCursor;
  325. FieldDefs: TfieldDefs);
  326. var
  327. C : TCursorName;
  328. I, FC: Integer;
  329. field: PMYSQL_FIELD;
  330. DFT: TFieldType;
  331. DFS: Integer;
  332. begin
  333. // Writeln('MySQL: Adding fielddefs');
  334. C:=(Cursor as TCursorName);
  335. If (C.FRes=Nil) then
  336. begin
  337. // Writeln('res is nil');
  338. MySQLError(c.FQMySQL,SErrNoQueryResult,Self);
  339. end;
  340. // Writeln('MySQL: have result');
  341. FC:=mysql_num_fields(C.FRes);
  342. For I:= 0 to FC-1 do
  343. begin
  344. field := mysql_fetch_field_direct(C.FRES, I);
  345. // Writeln('MySQL: creating fielddef ',I+1);
  346. if MySQLDataType(field^.ftype, field^.length, DFT, DFS) then
  347. TFieldDef.Create(FieldDefs, field^.name, DFT, DFS, False, I+1);
  348. end;
  349. // Writeln('MySQL: Finished adding fielddefs');
  350. end;
  351. function TConnectionName.Fetch(cursor: TSQLCursor): boolean;
  352. Var
  353. C : TCursorName;
  354. begin
  355. C:=Cursor as TCursorName;
  356. C.Row:=MySQL_Fetch_row(C.FRes);
  357. Result:=(C.Row<>Nil);
  358. end;
  359. function TConnectionName.LoadField(cursor : TSQLCursor;
  360. FieldDef : TfieldDef;buffer : pointer) : boolean;
  361. var
  362. I, FC, CT: Integer;
  363. field: PMYSQL_FIELD;
  364. row : MYSQL_ROW;
  365. C : TCursorName;
  366. begin
  367. // Writeln('LoadFieldsFromBuffer');
  368. C:=Cursor as TCursorName;
  369. if C.Row=nil then
  370. begin
  371. // Writeln('LoadFieldsFromBuffer: row=nil');
  372. MySQLError(c.FQMySQL,SErrFetchingData,Self);
  373. end;
  374. Row:=C.Row;
  375. FC := mysql_num_fields(C.FRES);
  376. for I := 0 to FC-1 do
  377. begin
  378. field := mysql_fetch_field_direct(C.FRES, I);
  379. if field^.name=FieldDef.name then break;
  380. Inc(Row);
  381. end;
  382. CT := MySQLWriteData(field^.ftype, field^.length, Row^, Buffer);
  383. result := true;
  384. end;
  385. function InternalStrToFloat(S: string): Extended;
  386. var
  387. I: Integer;
  388. Tmp: string;
  389. begin
  390. Tmp := '';
  391. for I := 1 to Length(S) do
  392. begin
  393. if not (S[I] in ['0'..'9', '+', '-', 'E', 'e']) then
  394. Tmp := Tmp + DecimalSeparator
  395. else
  396. Tmp := Tmp + S[I];
  397. end;
  398. Result := StrToFloat(Tmp);
  399. end;
  400. function InternalStrToDate(S: string): TDateTime;
  401. var
  402. EY, EM, ED: Word;
  403. begin
  404. EY := StrToInt(Copy(S,1,4));
  405. EM := StrToInt(Copy(S,6,2));
  406. ED := StrToInt(Copy(S,9,2));
  407. if (EY = 0) or (EM = 0) or (ED = 0) then
  408. Result:=0
  409. else
  410. Result:=EncodeDate(EY, EM, ED);
  411. end;
  412. function InternalStrToDateTime(S: string): TDateTime;
  413. var
  414. EY, EM, ED: Word;
  415. EH, EN, ES: Word;
  416. begin
  417. EY := StrToInt(Copy(S, 1, 4));
  418. EM := StrToInt(Copy(S, 6, 2));
  419. ED := StrToInt(Copy(S, 9, 2));
  420. EH := StrToInt(Copy(S, 11, 2));
  421. EN := StrToInt(Copy(S, 14, 2));
  422. ES := StrToInt(Copy(S, 17, 2));
  423. if (EY = 0) or (EM = 0) or (ED = 0) then
  424. Result := 0
  425. else
  426. Result := EncodeDate(EY, EM, ED);
  427. Result := Result + EncodeTime(EH, EN, ES, 0);
  428. end;
  429. function InternalStrToTime(S: string): TDateTime;
  430. var
  431. EH, EM, ES: Word;
  432. begin
  433. EH := StrToInt(Copy(S, 1, 2));
  434. EM := StrToInt(Copy(S, 4, 2));
  435. ES := StrToInt(Copy(S, 7, 2));
  436. Result := EncodeTime(EH, EM, ES, 0);
  437. end;
  438. function InternalStrToTimeStamp(S: string): TDateTime;
  439. var
  440. EY, EM, ED: Word;
  441. EH, EN, ES: Word;
  442. begin
  443. EY := StrToInt(Copy(S, 1, 4));
  444. EM := StrToInt(Copy(S, 5, 2));
  445. ED := StrToInt(Copy(S, 7, 2));
  446. EH := StrToInt(Copy(S, 9, 2));
  447. EN := StrToInt(Copy(S, 11, 2));
  448. ES := StrToInt(Copy(S, 13, 2));
  449. if (EY = 0) or (EM = 0) or (ED = 0) then
  450. Result := 0
  451. else
  452. Result := EncodeDate(EY, EM, ED);
  453. Result := Result + EncodeTime(EH, EN, ES, 0);;
  454. end;
  455. function TConnectionName.MySQLWriteData(AType: enum_field_types;ASize: Integer; Source, Dest: PChar): Integer;
  456. var
  457. VI: Integer;
  458. VF: Double;
  459. VD: TDateTime;
  460. Src : String;
  461. begin
  462. Result := 0;
  463. If (Source<>Nil) Then
  464. Src:=StrPas(Source)
  465. else
  466. Src:='';
  467. case AType of
  468. FIELD_TYPE_TINY, FIELD_TYPE_SHORT, FIELD_TYPE_LONG, FIELD_TYPE_LONGLONG,
  469. FIELD_TYPE_INT24:
  470. begin
  471. Result:=SizeOf(Integer);
  472. if (Src<>'') then
  473. VI := StrToInt(Src)
  474. else
  475. VI := 0;
  476. Move(VI, Dest^, Result);
  477. end;
  478. FIELD_TYPE_DECIMAL, FIELD_TYPE_FLOAT, FIELD_TYPE_DOUBLE:
  479. begin
  480. Result := SizeOf(Double);
  481. if Src <> '' then
  482. VF := InternalStrToFloat(Src)
  483. else
  484. VF := 0;
  485. Move(VF, Dest^, Result);
  486. end;
  487. FIELD_TYPE_TIMESTAMP:
  488. begin
  489. Result := SizeOf(TDateTime);
  490. if Src <> '' then
  491. VD := InternalStrToTimeStamp(Src)
  492. else
  493. VD := 0;
  494. Move(VD, Dest^, Result);
  495. end;
  496. FIELD_TYPE_DATETIME:
  497. begin
  498. Result := SizeOf(TDateTime);
  499. if Src <> '' then
  500. VD := InternalStrToDateTime(Src)
  501. else
  502. VD := 0;
  503. Move(VD, Dest^, Result);
  504. end;
  505. FIELD_TYPE_DATE:
  506. begin
  507. Result := SizeOf(TDateTime);
  508. if Src <> '' then
  509. VD := InternalStrToDate(Src)
  510. else
  511. VD := 0;
  512. Move(VD, Dest^, Result);
  513. end;
  514. FIELD_TYPE_TIME:
  515. begin
  516. Result := SizeOf(TDateTime);
  517. if Src <> '' then
  518. VD := InternalStrToTime(Src)
  519. else
  520. VD := 0;
  521. Move(VD, Dest^, Result);
  522. end;
  523. FIELD_TYPE_VAR_STRING, FIELD_TYPE_STRING, FIELD_TYPE_ENUM, FIELD_TYPE_SET:
  524. begin
  525. Result := ASize;
  526. { Write('Moving string of size ',asize,' : ');
  527. P:=Source;
  528. If (P<>nil) then
  529. While P[0]<>#0 do
  530. begin
  531. Write(p[0]);
  532. inc(p);
  533. end;
  534. Writeln;
  535. } if Src<> '' then
  536. Move(Source^, Dest^, Result)
  537. else
  538. Dest^ := #0;
  539. end;
  540. end;
  541. end;
  542. procedure TConnectionName.UpdateIndexDefs(var IndexDefs : TIndexDefs;TableName : string);
  543. var qry : TSQLQuery;
  544. begin
  545. if not assigned(Transaction) then
  546. DatabaseError(SErrConnTransactionnSet);
  547. qry := tsqlquery.Create(nil);
  548. qry.transaction := Transaction;
  549. qry.database := Self;
  550. with qry do
  551. begin
  552. ReadOnly := True;
  553. sql.clear;
  554. sql.add('show index from ' + TableName);
  555. open;
  556. end;
  557. while not qry.eof do with IndexDefs.AddIndexDef do
  558. begin
  559. Name := trim(qry.fieldbyname('Key_name').asstring);
  560. Fields := trim(qry.fieldbyname('Column_name').asstring);
  561. If Name = 'PRIMARY' then options := options + [ixPrimary];
  562. If qry.fieldbyname('Non_unique').asinteger = 0 then options := options + [ixUnique];
  563. qry.next;
  564. { while (name = qry.fields[0].asstring) and (not qry.eof) do
  565. begin
  566. Fields := Fields + ';' + trim(qry.Fields[2].asstring);
  567. qry.next;
  568. end;}
  569. end;
  570. qry.close;
  571. qry.free;
  572. end;
  573. function TConnectionName.GetTransactionHandle(trans: TSQLHandle): pointer;
  574. begin
  575. Result:=Nil;
  576. end;
  577. function TConnectionName.Commit(trans: TSQLHandle): boolean;
  578. begin
  579. // Do nothing.
  580. end;
  581. function TConnectionName.RollBack(trans: TSQLHandle): boolean;
  582. begin
  583. // Do nothing
  584. end;
  585. function TConnectionName.StartdbTransaction(trans: TSQLHandle; AParams : string): boolean;
  586. begin
  587. // Do nothing
  588. end;
  589. procedure TConnectionName.CommitRetaining(trans: TSQLHandle);
  590. begin
  591. // Do nothing
  592. end;
  593. procedure TConnectionName.RollBackRetaining(trans: TSQLHandle);
  594. begin
  595. // Do nothing
  596. end;
  597. end.