mysqlconn.inc 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  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): Integer;
  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, CT: 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. CT := MySQLWriteData(field^.ftype, field^.length, Row^, Buffer);
  390. result := true;
  391. end;
  392. function InternalStrToFloat(S: string): Extended;
  393. var
  394. I: Integer;
  395. Tmp: string;
  396. begin
  397. Tmp := '';
  398. for I := 1 to Length(S) do
  399. begin
  400. if not (S[I] in ['0'..'9', '+', '-', 'E', 'e']) then
  401. Tmp := Tmp + DecimalSeparator
  402. else
  403. Tmp := Tmp + S[I];
  404. end;
  405. Result := StrToFloat(Tmp);
  406. end;
  407. function InternalStrToDate(S: string): TDateTime;
  408. var
  409. EY, EM, ED: Word;
  410. begin
  411. EY := StrToInt(Copy(S,1,4));
  412. EM := StrToInt(Copy(S,6,2));
  413. ED := StrToInt(Copy(S,9,2));
  414. if (EY = 0) or (EM = 0) or (ED = 0) then
  415. Result:=0
  416. else
  417. Result:=EncodeDate(EY, EM, ED);
  418. end;
  419. function InternalStrToDateTime(S: string): TDateTime;
  420. var
  421. EY, EM, ED: Word;
  422. EH, EN, ES: Word;
  423. begin
  424. EY := StrToInt(Copy(S, 1, 4));
  425. EM := StrToInt(Copy(S, 6, 2));
  426. ED := StrToInt(Copy(S, 9, 2));
  427. EH := StrToInt(Copy(S, 12, 2));
  428. EN := StrToInt(Copy(S, 15, 2));
  429. ES := StrToInt(Copy(S, 18, 2));
  430. if (EY = 0) or (EM = 0) or (ED = 0) then
  431. Result := 0
  432. else
  433. Result := EncodeDate(EY, EM, ED);
  434. Result := Result + EncodeTime(EH, EN, ES, 0);
  435. end;
  436. function InternalStrToTime(S: string): TDateTime;
  437. var
  438. EH, EM, ES: Word;
  439. begin
  440. EH := StrToInt(Copy(S, 1, 2));
  441. EM := StrToInt(Copy(S, 4, 2));
  442. ES := StrToInt(Copy(S, 7, 2));
  443. Result := EncodeTime(EH, EM, ES, 0);
  444. end;
  445. function InternalStrToTimeStamp(S: string): TDateTime;
  446. var
  447. EY, EM, ED: Word;
  448. EH, EN, ES: Word;
  449. begin
  450. {$IFNDEF mysql40}
  451. EY := StrToInt(Copy(S, 1, 4));
  452. EM := StrToInt(Copy(S, 6, 2));
  453. ED := StrToInt(Copy(S, 9, 2));
  454. EH := StrToInt(Copy(S, 12, 2));
  455. EN := StrToInt(Copy(S, 15, 2));
  456. ES := StrToInt(Copy(S, 18, 2));
  457. {$ELSE}
  458. EY := StrToInt(Copy(S, 1, 4));
  459. EM := StrToInt(Copy(S, 5, 2));
  460. ED := StrToInt(Copy(S, 7, 2));
  461. EH := StrToInt(Copy(S, 9, 2));
  462. EN := StrToInt(Copy(S, 11, 2));
  463. ES := StrToInt(Copy(S, 13, 2));
  464. {$ENDIF}
  465. if (EY = 0) or (EM = 0) or (ED = 0) then
  466. Result := 0
  467. else
  468. Result := EncodeDate(EY, EM, ED);
  469. Result := Result + EncodeTime(EH, EN, ES, 0);;
  470. end;
  471. function TConnectionName.MySQLWriteData(AType: enum_field_types;ASize: Integer; Source, Dest: PChar): Integer;
  472. var
  473. VI: Integer;
  474. VF: Double;
  475. VD: TDateTime;
  476. Src : String;
  477. begin
  478. Result := 0;
  479. If (Source<>Nil) Then
  480. Src:=StrPas(Source)
  481. else
  482. Src:='';
  483. case AType of
  484. FIELD_TYPE_TINY, FIELD_TYPE_SHORT, FIELD_TYPE_LONG, FIELD_TYPE_LONGLONG,
  485. FIELD_TYPE_INT24:
  486. begin
  487. Result:=SizeOf(Integer);
  488. if (Src<>'') then
  489. VI := StrToInt(Src)
  490. else
  491. VI := 0;
  492. Move(VI, Dest^, Result);
  493. end;
  494. {$ifdef mysql50}
  495. FIELD_TYPE_NEWDECIMAL,
  496. {$endif}
  497. FIELD_TYPE_DECIMAL, FIELD_TYPE_FLOAT, FIELD_TYPE_DOUBLE:
  498. begin
  499. Result := SizeOf(Double);
  500. if Src <> '' then
  501. VF := InternalStrToFloat(Src)
  502. else
  503. VF := 0;
  504. Move(VF, Dest^, Result);
  505. end;
  506. FIELD_TYPE_TIMESTAMP:
  507. begin
  508. Result := SizeOf(TDateTime);
  509. if Src <> '' then
  510. VD := InternalStrToTimeStamp(Src)
  511. else
  512. VD := 0;
  513. Move(VD, Dest^, Result);
  514. end;
  515. FIELD_TYPE_DATETIME:
  516. begin
  517. Result := SizeOf(TDateTime);
  518. if Src <> '' then
  519. VD := InternalStrToDateTime(Src)
  520. else
  521. VD := 0;
  522. Move(VD, Dest^, Result);
  523. end;
  524. FIELD_TYPE_DATE:
  525. begin
  526. Result := SizeOf(TDateTime);
  527. if Src <> '' then
  528. VD := InternalStrToDate(Src)
  529. else
  530. VD := 0;
  531. Move(VD, Dest^, Result);
  532. end;
  533. FIELD_TYPE_TIME:
  534. begin
  535. Result := SizeOf(TDateTime);
  536. if Src <> '' then
  537. VD := InternalStrToTime(Src)
  538. else
  539. VD := 0;
  540. Move(VD, Dest^, Result);
  541. end;
  542. FIELD_TYPE_VAR_STRING, FIELD_TYPE_STRING, FIELD_TYPE_ENUM, FIELD_TYPE_SET:
  543. begin
  544. Result := ASize;
  545. { Write('Moving string of size ',asize,' : ');
  546. P:=Source;
  547. If (P<>nil) then
  548. While P[0]<>#0 do
  549. begin
  550. Write(p[0]);
  551. inc(p);
  552. end;
  553. Writeln;
  554. } if Src<> '' then
  555. Move(Source^, Dest^, Result)
  556. else
  557. Dest^ := #0;
  558. end;
  559. end;
  560. end;
  561. procedure TConnectionName.UpdateIndexDefs(var IndexDefs : TIndexDefs;TableName : string);
  562. var qry : TSQLQuery;
  563. begin
  564. if not assigned(Transaction) then
  565. DatabaseError(SErrConnTransactionnSet);
  566. qry := tsqlquery.Create(nil);
  567. qry.transaction := Transaction;
  568. qry.database := Self;
  569. with qry do
  570. begin
  571. ReadOnly := True;
  572. sql.clear;
  573. sql.add('show index from ' + TableName);
  574. open;
  575. end;
  576. while not qry.eof do with IndexDefs.AddIndexDef do
  577. begin
  578. Name := trim(qry.fieldbyname('Key_name').asstring);
  579. Fields := trim(qry.fieldbyname('Column_name').asstring);
  580. If Name = 'PRIMARY' then options := options + [ixPrimary];
  581. If qry.fieldbyname('Non_unique').asinteger = 0 then options := options + [ixUnique];
  582. qry.next;
  583. { while (name = qry.fields[0].asstring) and (not qry.eof) do
  584. begin
  585. Fields := Fields + ';' + trim(qry.Fields[2].asstring);
  586. qry.next;
  587. end;}
  588. end;
  589. qry.close;
  590. qry.free;
  591. end;
  592. function TConnectionName.GetTransactionHandle(trans: TSQLHandle): pointer;
  593. begin
  594. Result:=Nil;
  595. end;
  596. function TConnectionName.Commit(trans: TSQLHandle): boolean;
  597. begin
  598. // Do nothing.
  599. end;
  600. function TConnectionName.RollBack(trans: TSQLHandle): boolean;
  601. begin
  602. // Do nothing
  603. end;
  604. function TConnectionName.StartdbTransaction(trans: TSQLHandle; AParams : string): boolean;
  605. begin
  606. // Do nothing
  607. end;
  608. procedure TConnectionName.CommitRetaining(trans: TSQLHandle);
  609. begin
  610. // Do nothing
  611. end;
  612. procedure TConnectionName.RollBackRetaining(trans: TSQLHandle);
  613. begin
  614. // Do nothing
  615. end;
  616. end.