Data.Provider.Temp.pas 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. unit Data.Provider.Temp;
  2. interface
  3. uses
  4. FireDAC.Comp.Client, System.Classes, FireDAC.Comp.UI, System.SysUtils,
  5. System.Generics.Collections, FireDAC.Phys.SQLite;
  6. type
  7. TBaseProvider = class(TInterfacedObject)
  8. private
  9. public
  10. protected
  11. procedure Init(ATableName: string; ACreateTableSql: string);
  12. end;
  13. implementation
  14. uses
  15. BaseDataModule;
  16. var
  17. _query: TFDQuery;
  18. _connection: TFDConnection;
  19. _driverLink: TFDPhysSQLiteDriverLink;
  20. _waitCursor: TFDGUIxWaitCursor;
  21. const
  22. USERS_TABLE_NAME: string = 'Users';
  23. USERS_CREATE_TABLE: string = 'CREATE TABLE Users('+
  24. 'LoginName string(50), ' +
  25. 'DisplayName string(50), ' +
  26. 'ServerID string(50), ' +
  27. 'Version Integer, ' +
  28. 'Sex byte)';
  29. USERS_INSERT: string =
  30. 'Insert into Users(LoginName, DisplayName, ServerID, Version, Sex) ' +
  31. 'Values(:LoginName, :DisplayName, :ServerID, :Version, :Sex)';
  32. USERS_UPDATE: string = 'Update Users Set DisplayName = :DisplayName, ' +
  33. 'Version = :Version, ' +
  34. 'Sex = :Sex, ' +
  35. 'Where LoginName = :LoginName and ServerID = :ServerID';
  36. USERS_DELETE: string = 'Delete from Users where LoginName = :LoginName and ServerID = :ServerID';
  37. USERS_SELETE_ONE: string = 'Selete LoginName, DisplayName, ServerID, Version, Sex From Users ' +
  38. 'Where LoginName = :LoginName and ServerID = :ServerID';
  39. USERS_SELETE_ALL: string = 'Selete LoginName, DisplayName, ServerID, Version, Sex From Users ' +
  40. 'Where ServerID = :ServerID';
  41. { TTempProvider }
  42. procedure TBaseProvider.Init(ATableName: string; ACreateTableSql: string);
  43. var
  44. list: TStringList;
  45. str: string;
  46. AConnection: TFDCustomConnection;
  47. begin
  48. AConnection := BaseDataModel.GetConnection;
  49. list := TStringList.Create;
  50. try
  51. AConnection.GetTableNames('','','',list);
  52. for str in list do
  53. if string.Compare(str, ATableName, true) = 0 then
  54. Exit;
  55. AConnection.ExecSQL(ACreateTableSql);
  56. finally
  57. end;
  58. list.Destroy;
  59. end;
  60. initialization
  61. {_query := TFDQuery.Create(nil);
  62. _connection := TFDConnection.Create(nil);
  63. _driverLink := TFDPhysSQLiteDriverLink.Create(nil);
  64. _waitCursor := TFDGUIxWaitCursor.Create(nil);
  65. _connection.Params.Add('DriverID=SQLite');
  66. _connection.Params.Add('Database=Data\temp.dat'); }
  67. finalization
  68. end.