0 Members and 1 Guest are viewing this topic.
var MyTable: TMySSQL_Table;procedure ActivateServer();begin if (not(CreateTable(MyTable, 'tablename'))) then begin WriteLn('Unable to create a new table, reason: ' + MyTable.Exception); end;end;
var MyTable: TMySSQL_Table;procedure ActivateServer();begin if (not(CreateTable(MyTable, 'tablename'))) then begin WriteLn('Unable to create a new table, reason: ' + MyTable.Exception); end; DestroyTable(MyTable);end;
var MyTable: TMySSQL_Table;procedure ActivateServer();begin if (not(LoadTable(MyTable, 'tablename'))) then begin WriteLn('Failed to load table, reason:' + MyTable.Exception); end;end;
var MyTable: TMySSQL_Table;procedure ActivateServer();begin if (not(LoadTable(MyTable, 'tablename'))) then begin WriteLn('Failed to load table, reason:' + MyTable.Exception); end; if (not(UnloadTable(MyTable))) then begin WriteLn('Could not unload table, reason: ' + MyTable.Exception); end;end;
var MyTable: TMySSQL_Table;procedure ActivateServer();begin if (not(CreateTable(MyTable, 'new_tablename'))) then begin WriteLn('Unable to create a new table, reason: ' + MyTable.Exception); end; if (not(SaveTable(MyTable))) then begin WriteLn('Could not save table, reason: ' + MyTable.Exception); end;end;
var MyTable: TMySSQL_Table;procedure ActivateServer();begin if (not(CreateTable(MyTable, 'tablename'))) then begin WriteLn('Unable to create a new table, reason: ' + MyTable.Exception); end; WriteLn('New row created. Index: ' + IntToStr(CreateRow(MyTable, [20, 'data', 12.5, true])));end;
var MyTable: TMySSQL_Table; MyColumn: TMySSQL_Column; Index: word;procedure ActivateServer();begin if (CreateTable(MyTable, 'accounts')) then begin Index:= CreateRow(MyTable, ['Curry', 'password', true]); if (FetchColumn(MyTable, Index, 0, MyColumn)) then begin WriteLn('Username: ' + MyColumn.Value); // Output: "Username: Curry" end else begin WriteLn('Unable to fetch column, reason: ' + MyTable.Exception); end; end else begin WriteLn('Unable to create a new table, reason: ' + MyTable.Exception); end;end;
var MyTable: TMySSQL_Table; Index: integer;procedure ActivateServer();begin if (CreateTable(MyTable, 'accounts')) then begin CreateRow(MyTable, ['Curry', 'password', true]); Index:= FetchRowByColumn(MyTable, 0, 'Curry'); if (Index > -1) then begin WriteLn('Row index of account Curry: ' + IntToStr(Index)); // Output: "Row index of account Curry: 0" end else begin WriteLn('No row found'); end; end else begin WriteLn('Unable to create a new table, reason: ' + MyTable.Exception); end;end;
var MyTable: TMySSQL_Table; Index: word;procedure ActivateServer();begin if (CreateTable(MyTable, 'animals')) then begin Index:= CreateRow(MyTable, ['dogs', 'cats', 'horses']); if (SetColumn(MyTable, Index, 2, 90)) then begin WriteLn('Column successfully updated'); end else begin WriteLn('Could not update column, reason: ' + MyTable.Exception); end; end else begin WriteLn('Unable to create a new table, reason: ' + MyTable.Exception); end;end;
var MyTable: TMySSQL_Table; Index: word;procedure ActivateServer();begin if (CreateTable(MyTable, 'nature')) then begin Index:= CreateRow(MyTable, ['nature', 'tree']); if (AppendColumn(MyTable, Index, 'flower')) then begin WriteLn('Successfully appended a new column'); end else begin WriteLn('Could not append a new column, reason: ' + MyTable.Exception); end; end else begin WriteLn('Unable to create a new table, reason: ' + MyTable.Exception); end;end;
var MyTable: TMySSQL_Table; Index: word;procedure ActivateServer();begin if (CreateTable(MyTable, 'nature')) then begin Index:= CreateRow(MyTable, ['nature', 'tree', 'flower']); if (CacheRow(MyTable, Index)) then begin WriteLn('Row cached'); // You can now use CFetchColumn, CSetColumnand and CIncColumn to fetch/set columns // or use the alternative syntax, which is not recommended, but for the sake of this script, here it is... WriteLn(MyTable.Rows[Index].Columns[2].Value) // Output: "flower" MyTable.Rows[Index].Columns[2].Value:= 'rose'; WriteLn(MyTable.Rows[Index].Columns[2].Value) // Output: "rose" end else begin WriteLn('Failed to cache row: ' + MyTable.Exception); end; end else begin WriteLn('Unable to create a new table, reason: ' + MyTable.Exception); end;end;
var MyTable: TMySSQL_Table; Index: word;procedure ActivateServer();begin if (CreateTable(MyTable, 'nature')) then begin Index:= CreateRow(MyTable, ['nature', 'tree', 'flower', 'daffodil']); if (CacheRow(MyTable, Index)) then begin WriteLn('Row cached'); // Use CFetchColumn, CSetColumn and CIncColumn here UncacheRow(MyTable, Index); // Using CFetchColumn, CSetColumn and CIncColumn now will result into a MySSQL exception and can be "catched" with MyTable.Exception end else begin WriteLn('Could not cache row, reason: ' + MyTable.Exception); end; end else begin WriteLn('Unable to create a new table, reason: ' + MyTable.Exception); end;end;
var MyTable: TMySSQL_Table; Index: word;procedure ActivateServer();begin if (CreateTable(MyTable, 'nature')) then begin Index:= CreateRow(MyTable, ['nature', 'tree', 'flower', 'daffodil']); if (CacheRow(MyTable, Index)) then begin if (CFetchColumn(MyTable, Index, 0) <> '') then begin WriteLn('Value is: ' + CFetchColumn(MyTable, Index, 0)); // Output: "Value is: nature" end else begin WriteLn('Failed to fetch column, reason: ' + MyTable.Exception); end; UncacheRow(MyTable, Index); end else begin WriteLn('Could not cache row, reason: ' + MyTable.Exception); end; end else begin WriteLn('Unable to create a new table, reason: ' + MyTable.Exception); end;end;
var MyTable: TMySSQL_Table; Index: word;procedure ActivateServer();begin if (CreateTable(MyTable, 'nature')) then begin Index:= CreateRow(MyTable, ['nature', 'tree', 'flower', 'daffodil']); if (CacheRow(MyTable, Index)) then begin CSetColumn(MyTable, Index, 3, 'rose'); if (CFetchColumn(MyTable, Index, 3)) then begin WriteLn('New value is: ' + CFetchColumn(MyTable, Index, 3)); // Output: "New value is: rose" end else begin WriteLn('Failed to fetch column, reason: ' + MyTable.Exception); end; UncacheRow(MyTable, Index); end else begin WriteLn('Could not cache row, reason: ' + MyTable.Exception); end; end else begin WriteLn('Unable to create a new table, reason: ' + MyTable.Exception); end;end;
var MyTable: TMySSQL_Table; Index: word;procedure ActivateServer();begin if (CreateTable(MyTable, 'math')) then begin Index:= CreateRow(MyTable, ['20', 12, '155']); if (CacheRow(MyTable, Index)) then begin CIncColumn(MyTable, Index, 2, 5); if (CFetchColumn(MyTable, Index, 2)) then begin WriteLn('New value is: ' + CFetchColumn(MyTable, Index, 2)); // Output: "New value is: 160" end else begin WriteLn('Failed to fetch column, reason: ' + MyTable.Exception); end; UncacheRow(MyTable, Index); end else begin WriteLn('Could not cache row, reason: ' + MyTable.Exception); end; end;end;
function _RowExists(Row: integer): boolean;begin if (ArrayHigh(database) >= Row) then begin result:= true; end;end;
function _RowExists(Row: integer): boolean;begin result := ArrayHigh(database) >= Row;end;
const _FOLDER_DATABASE = ''; _NAME_DATABASE = 'database.txt';var database: array of string;function IXSplit(const SOURCE: string; Delimiter: string): array of string;var i, x, d: integer; s, b: string;begin d:= length(Delimiter); i:= 1; SetArrayLength(Result, 0); while (i <= length(SOURCE)) do begin s:= Copy(SOURCE, i, d); if (s = Delimiter) then begin SetArrayLength(Result, x + 1); Result[x]:= b; Inc(i, d); Inc(x, 1); b:= ''; end else begin b:= b + Copy(s, 1, 1); Inc(i, 1); end; end; if (b <> '') then begin SetArrayLength(Result, x + 1); Result[x]:= b; end;end;function ReadFromFile(File: string): string;begin Result:= ReadFile(File); Result:= Copy(Result, 0, length(Result) - 2);end;function DoesFileExist(Name: string): boolean;begin if (GetSystem() = 'windows') then begin if (FileExists(Name)) then begin result:= true; end; end else begin if ((FileExists(Name)) or (ReadFromFile(Name) <> '')) then begin result:= true; end; end;end;procedure _LoadDatabase();begin if (DoesFileExist(_FOLDER_DATABASE + _NAME_DATABASE)) then begin database:= IXSplit(ReadFromFile(_FOLDER_DATABASE + _NAME_DATABASE), #13#10); end else begin WriteFile(_FOLDER_DATABASE + _NAME_DATABASE, ''); end;end; procedure _SaveDatabase();var i: integer; b: string;begin for i:= 0 to GetArrayLength(database) - 1 do begin if (Trim(database[i]) <> '') then begin if (b <> '') then begin b:= b + #13#10 + database[i]; end else begin b:= database[i]; end; end; end; SetArrayLength(database, 0); if (b <> '') then begin database:= IXSplit(b, #13#10); end; WriteFile(_FOLDER_DATABASE + _NAME_DATABASE, b);end;function _RowExists(Row: integer): boolean;begin result:= ArrayHigh(database) >= Row;end;function _getColumnInfo(Row, Column: integer): integer;var ch, x, tabs: integer; b: string;begin tabs:= -1; b:= database[Row]; while (tabs <> Column) do begin x:= StrPos(#9, b); if ((x = 0) and (tabs <> Column)) then begin exit; end; Inc(tabs, 1); if (tabs = Column) then begin result:= ch + 1; break; end else begin ch:= ch + x; Delete(b, 1, x); end; end;end;function GetTypeOF(Value: variant): string;begin case VarType(Value) of 3 : result:= IntToStr(Value); 5 : result:= FloatToStr(Value); 11 : result:= iif(Value, 'true', 'false'); 256: result:= Value; else result:= 'unknown Type'; end;end;procedure _CreateRow(Columns: array of variant);var i, x: integer;begin SetArrayLength(database, GetArrayLength(database) + 1); x:= GetArrayLength(database) - 1; for i:= 0 to GetArrayLength(Columns) - 1 do begin database[x]:= database[x] + GetTypeOF(Columns[i]) + #9; end; _SaveDatabase();end;function _DeleteRow(Row: integer): boolean;begin if (_RowExists(Row)) then begin database[Row]:= ''; _SaveDatabase(); result:= true; end;end;function _UpdateColumn(Row, Column, Increase: integer): string;var pos: integer; data: string;begin if (_RowExists(Row)) then begin pos:= _getColumnInfo(Row, Column); if (pos > 0) then begin data:= GetPiece(database[Row], #9, Column); if (RegExpMatch('^-?\d+$', data)) then begin result:= IntToStr(StrToInt(data) + Increase); Delete(database[Row], pos, length(data)); Insert(result, database[Row], pos); end; end; end;end;function _SetColumn(Row, Column: integer; Value: variant): boolean;var pos: integer; data: string;begin if (_RowExists(Row)) then begin pos:= _getColumnInfo(Row, Column); if (pos > 0) then begin data:= GetPiece(database[Row], #9, Column); Delete(database[Row], pos, length(data)); Insert(GetTypeOF(Value), database[Row], pos); result:= true; end; end;end;function _AppendColumn(Row: integer; Value: string): boolean;begin if (_RowExists(Row)) then begin database[Row]:= database[Row] + Value + #9; result:= true; end;end;procedure ActivateServer();begin _LoadDatabase();end;
string 12 true -22.45
- Implemented a new method to save and delete rows (SwapSQLRowID()), which is much faster than using XSplit Hence it avoids frequent crashes caused by calling XSplit too much Note: Every time a row is deleted you have to refresh your "row pointers" because the new method swaps to RowIDs- Renamed _SaveDatabase() to _SnapDatabase() and cleaned up the code a bit- Renamed Row to RowID for every function which expects this parameter to be passed on
- added OnErrorOccur() function which holds the last error occured in the new variable Exception In case a MySSQL function such as _Update-, _Set-, _Append-, _DeleteColumn wasn't successful you can output the last exception with WriteLn() Example: if (not(_SetColumn(RowID, ColumnID, Value))) then begin WriteLn(Exception); end;- _UpdateColumn() supports now float values and returns a boolean instead of a string- _AppendColumn() supports now variants as value
const MySSQL = 'MySSQL';procedure Initialize();begin CrossFunc([], MySSQL + '._Initialize');end;procedure SelectDatabase(const NAME_DATABASE: string);begin CrossFunc([NAME_DATABASE], MySSQL + '._SelectDatabase');end;procedure SnapDatabase();begin CrossFunc([], MySSQL + '._SnapDatabase');end;function GetColumnItem(RowID, ColumnID: integer): string;begin Result:= CrossFunc([RowID, ColumnID], MySSQL + '._GetColumnItem');end;function CreateRow(ColumnItems: array of variant): integer;begin Result:= CrossFunc([ColumnItems], MySSQL + '._CreateRow');end;function DeleteRow(RowID: integer): boolean;begin Result:= CrossFunc([RowID], MySSQL + '._DeleteRow');end;function UpdateColumn(RowID, ColumnID: integer; Increase: extended): boolean;begin Result:= CrossFunc([RowID, ColumnID, Increase], MySSQL + '._UpdateColumn');end;function SetColumn(RowID, ColumnID: integer; Value: variant): boolean;begin Result:= CrossFunc([RowID, ColumnID, Value], MySSQL + '._SetColumn');end;function AppendColumn(RowID: integer; Value: variant): boolean;begin Result:= CrossFunc([RowID, Value], MySSQL + '._AppendColumn');end;[/code ]
Quick question, where exactly is SQL here (apart from the name) ?
Then it shouldn't be in the name.
Fortunately, in one of the next server releases eC has promised to support SQLITE support, which will render this abomination deprecated.
Quote from: jrgp on July 27, 2009, 10:03:01 amFortunately, in one of the next server releases eC has promised to support SQLITE support, which will render this abomination deprecated.Not really. Those who don't have any SQL database to connect to can still use this as an alternative. This may also be used for those using older versions of Soldat Dedicated Server as well.
Not really. SQLITE doesn't use a database "to connect to." With it, the "database" is all in one local file, which is accessed.
Quote from: jrgp on July 27, 2009, 03:34:23 pmNot really. SQLITE doesn't use a database "to connect to." With it, the "database" is all in one local file, which is accessed.It creates/hosts a database?
SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine.