Author Topic: MySSQL  (Read 10716 times)

0 Members and 1 Guest are viewing this topic.

Offline CurryWurst

  • Camper
  • ***
  • Posts: 265
    • Soldat Global Account System
MySSQL
« on: April 09, 2009, 07:08:54 pm »
Script Name: MySSQL
Script Description Database functions to manage your own database.
Author: CurryWurst
Compile Test: Passed
Core Version: 2.6.5

MySSQL v2.1 syntax examples & descriptions

function CreateTable(var Table: TMySSQL_Table; const Tablename: string): boolean;

Creates a new table file and links a TMySSQL_Table object against it.
Returns true, if the table has been created and loaded into the TMySSQL_Table object.
Tables are stored in ".myssql" files in the folder "./tables" of your soldat servers' root directory. Grant at least 755 rights to this folder (for linux users only).

Code: (pascal) [Select]
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;



procedure DestroyTable(var Table: TMySSQL_Table);

Unloads a TMySSQL_Table object and unlinks it from the table file. The table will not be saved.
You may reuse the TMySSQL_Table object you passed for other tables after calling this procedure.

Code: (pascal) [Select]
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;



function LoadTable(var Table: TMySSQL_Table; const Tablename: string): boolean;

Loads a table from a file into a TMySSQL_Table object and links the object against the table file.
If this function is not successful, it will return false and the TMySSQL_Table object will not be modified.

Code: (pascal) [Select]
var
  MyTable: TMySSQL_Table;

procedure ActivateServer();
begin
  if (not(LoadTable(MyTable, 'tablename'))) then
  begin
    WriteLn('Failed to load table, reason:' + MyTable.Exception);
  end;
end;



function UnloadTable(var Table: TMySSQL_Table): boolean;

Saves the table of a TMySSQL_Table object (if it has been modified), unloads it and unlinks it from the table file.
Returns true, in case the function was successful.
TMySSQL_Table object can be reused for other tables after calling this function.

Code: (pascal) [Select]
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;



function SaveTable(var Table: TMySSQL_Table): boolean;

Saves the table of a TMySSQL_Table object into the file it's linked against.
Returns true, if the table was saved successfully.

Code: (pascal) [Select]
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;



function CreateRow(var Table: TMySSQL_Table; const Columns: array of variant): word;

Creates a new row in your table. Columns can be of any variable type.
Returns the row index of the newly created row. You may save this index to access this row later on.

Code: (pascal) [Select]
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;



function DestroyRow(var Table: TMySSQL_Table; const Row: word): boolean;

Removes a row from your table, whereas the parameter Row (index which you received from calling CreateRow) specifies which row is to be removed.
If the row was removed successfully, the function will return true.
Please note that this function may change the order of your rows within the table. Hence, if you saved indexes of rows you need to refresh them. Normally, the index of your last row will be the index of the row you removed, i.e. assume you got a table with three rows with the indexes 0, 1, 2 and you delete the second row (index = 1), the third row will have the index 1.



function FetchColumn(var Table: TMySSQL_Table; const Row, Column: word; var DummyC: TMySSQL_Column): boolean;

"Slow" function to fetch a record of a column. Requires to have a object of the type TMySSQL_Column passed on.
Your TMySSQL_Column object will contain the value of your column record, in case the function was called successfully.
Returns true, if the column record could be fetched.

Code: (pascal) [Select]
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;



function FetchRowByColumn(var Table: TMySSQL_Table; const Column: word; const Value: variant): integer;

Particular function to fetch a row by a (unique) column record. Especially for nick based account systems.
Searches for a row in which the column Column (= index of the column) contains the record Value. Value can be of any variable type.
If a row which matches the condition was found, it will return the row index, if not the index will be -1.

Code: (pascal) [Select]
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;



function SetColumn(var Table: TMySSQL_Table; const Row, Column: word; const Value: variant): boolean;

"Slow" function to set the record of a column of a row to any value you want it to be.
Returns true, if the column record was set to the new value.

Code: (pascal) [Select]
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;



function AppendColumn(var Table: TMySSQL_Table; const Row: word; const Value: variant): boolean;

Appends a new column to the end of each row.
In case the function is successfully, it will return true,

Code: (pascal) [Select]
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;



function CacheRow(var Table: TMySSQL_Table; const Row: word): boolean;

Loads a row and all its columns into the cache and grants it very fast fetch/set time.
You always should prefer to cache rows, you want to fetch or set columns from, if you are going to access these rows more than one time, instead of using FetchColumn and SetColumn.
Returns true, if the function is successful and allows you to fetch/set columns via CFetchColumn/CSetColumnand CIncColumn. Alternatively, you can set or fetch columns by accessing the variables of a TMySSQL_Table object...

Code: (pascal) [Select]
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;



procedure UncacheRow(var Table: TMySSQL_Table; const Row: word);

Removes a row from the cache and disables the functions CFetchColumn, CSetColumn and CIncColumn for it.
If you don't need to access a row anymore, you always should remove it from the cache.

Code: (pascal) [Select]
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;



function CFetchColumn(var Table: TMySSQL_Table; const Row, Column: word): string;

Very fast function to fetch a column record of a row.
Returns a blank string in case the column record is blank or does not exist, but I doubt you will make use of blank columns, so checking CFetchColumn against <> '' is a good way to determine whether it failed or not.

Code: (pascal) [Select]
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;

function CSetColumn(var Table: TMySSQL_Table; const Row, Column: word; const Value: variant): boolean;

Very fast function to set a column record of a row to any value you want it to be. Requires the row, you want to set a column of, to be cached.
If this function succeeds, it will return true.

Code: (pascal) [Select]
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;



function CIncColumn(var Table: TMySSQL_Table; const Row, Column: word; const Increase: extended): boolean;

Very fast function to increase a column representing a numeric value, including float values.
Returns true, if the column has been increased or rather decreased if Increase is negative.

Code: (pascal) [Select]
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;

Actually it is not necessary to check whether a MySSQL function/procedure call was successfully, but I implemented it to show you how you can "catch" possible exceptions. Most time calls to functions or rather procedures will succeed, unless you handle them wrong and pass on an invalid row index to a function for example.

« Last Edit: February 11, 2013, 03:07:08 pm by CurryWurst »
Soldat Global Account System: #soldat.sgas @ quakenet

Offline iDante

  • Veteran
  • *****
  • Posts: 1967
Re: Simple Database Functions
« Reply #1 on: April 09, 2009, 07:24:57 pm »
EnEsCe recently said in his blog that he wanted to include MySQL into the next scriptcore if at all possible. If that doesn't work out then this is almost as good :)

Nice work!

Offline scarface09

  • Veteran
  • *****
  • Posts: 1153
  • Arsenal Supporter For Life
Re: Simple Database Functions
« Reply #2 on: April 09, 2009, 08:40:40 pm »
Cool script. Yes EnEsCe did say that in his blog. Will this be good enough don't you think? Although this would be a good other choice if he doesn't work out making what he wants.
Football is the other face of the world. If you don't like it, then you can get the hell out!

Offline y0uRd34th

  • Camper
  • ***
  • Posts: 325
  • [i]Look Signature![/i]
Re: Simple Database Functions
« Reply #3 on: April 10, 2009, 05:45:37 am »
Good work Curry!
It was time that someone releases sth. like this.  ;)

Look there:
Code: [Select]
function _RowExists(Row: integer): boolean;
begin
   if (ArrayHigh(database) >= Row) then
   begin
     result:= true;
   end;
end;
If you have an function that returns an Boolean, the Result normally is set to true.
And if you have only one Result that returns true, the Result would be
always true or not? Tell me if I'm wrong.
(Hope you check my English explaining skill..)

Offline JFK

  • Camper
  • ***
  • Posts: 255
    • My TraxInSpace Account
Re: Simple Database Functions
« Reply #4 on: April 10, 2009, 07:15:54 am »
Excellent script. Seems very efficient.
I think in some cases it might be better to spread large databases over multiple files. But having too much files in a directory can also be a bad thing.

As for the boolean: pretty sure it's default state is false.
Putting a small extra line for clearity would be good practice imo :p
Come join: EliteCTF
Listen to: My Music

Offline iDante

  • Veteran
  • *****
  • Posts: 1967
Re: Simple Database Functions
« Reply #5 on: April 10, 2009, 09:26:04 am »
Boolean is set to false, numbers are 0.0, arrays have 0 elements (unless otherwise specified).
Pascal is nice that way :)

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: Simple Database Functions
« Reply #6 on: April 10, 2009, 10:33:38 am »
I prefer having a Result := false; just in case, but I would probably do this to keep it shorter:
Code: [Select]
function _RowExists(Row: integer): boolean;
begin
  result := ArrayHigh(database) >= Row;
end;
But what is there should be fine.

Offline CurryWurst

  • Camper
  • ***
  • Posts: 265
    • Soldat Global Account System
Re: MySSQL
« Reply #7 on: April 19, 2009, 08:40:19 am »
Script updated...

- Fixed a very stupid bug where it was not possible to create a new row
- Modified _RowExists according to DorkeyDear's idea
- Renamed script to MySSQL (My Soldat SQL)

I highly recommend to redownload the script because CreateRow should
work now.
Soldat Global Account System: #soldat.sgas @ quakenet

Offline CurryWurst

  • Camper
  • ***
  • Posts: 265
    • Soldat Global Account System
Re: MySSQL
« Reply #8 on: May 20, 2009, 01:16:43 pm »
Here's the second update if someone is interested in the script...

Code: [Select]
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;

I'll upload the update to soldatcentral later.

The update makes life much more comfortable when you're dealing with databases.

To create a new row with columns or to set an existing column you don't have to convert all variables into strings anymore.
Pass on every type (integers/strings/floating-point number/booleans) you want without using strings.
The delimiter "#9" is also not required anymore.

The input is now an array of variant, therefore you may do things like this:

_CreateRow(['string', 12, true, -22.45]);
_SetColumn(0, 1, 12.0);

The first command above will result into ...
Code: [Select]
string 12 true -22.45
in your database file.

I also added a function to check if a file exists.

Have fun creating your own databases :D
« Last Edit: May 22, 2009, 05:43:15 am by CurryWurst »
Soldat Global Account System: #soldat.sgas @ quakenet

Offline CurryWurst

  • Camper
  • ***
  • Posts: 265
    • Soldat Global Account System
Re: MySSQL
« Reply #9 on: June 13, 2009, 04:22:54 pm »
According to the new LogInSystem update I created an update for MySSQL.
It speeds up the performance of creating and deleting rows as well as saving the complete database significant.
I highlighted the specific lines in the code for the new method.

Here's the changelog for the second update:

Code: [Select]
- 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

EDIT: I made a third update to MySSQL:

Code: [Select]
- 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



(Size 1.64 KB)
- http://soldatcentral.com/index.php?page=script&f=109 -


** Script hosted by Soldat Central! Please visit the author's script page and Rate this script **
« Last Edit: June 14, 2009, 08:22:03 am by CurryWurst »
Soldat Global Account System: #soldat.sgas @ quakenet

Offline Zabijaka

  • Soldier
  • **
  • Posts: 201
  • Soldat Fan, Hitman Fan
Re: MySSQL
« Reply #10 on: July 24, 2009, 04:21:46 pm »
I have stupid question - if I make another script (ex. stats), it's possible to another script use functions from this script without itegration these two scripts ??

Offline CurryWurst

  • Camper
  • ***
  • Posts: 265
    • Soldat Global Account System
Re: MySSQL
« Reply #11 on: July 24, 2009, 05:24:59 pm »
Yes it is if you use CrossFunc to separate MySSQL from your script. I haven't written all of these CrossFunc functions yet, but they will be included in the next update which will be out soon. If you don't want to wait, you may write these functions on your own.

Here are some example codes, written a few days ago by me, how to separate the script. Not all of them may be correct, because they already contain code from the upcomming update.

Code: (Pascal) [Select]
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 ]

They have to be implemented in your script to allow the use of MySSQL.
« Last Edit: July 24, 2009, 05:30:17 pm by CurryWurst »
Soldat Global Account System: #soldat.sgas @ quakenet

Offline Quantifier

  • Major
  • *
  • Posts: 70
Re: MySSQL
« Reply #12 on: July 27, 2009, 04:39:45 am »
Quick question, where exactly is SQL here (apart from the name) ?

Offline jrgp

  • Administrator
  • Flamebow Warrior
  • *****
  • Posts: 5037
Re: MySSQL
« Reply #13 on: July 27, 2009, 08:46:57 am »
Quick question, where exactly is SQL here (apart from the name) ?
No where.
There are other worlds than these

Offline Quantifier

  • Major
  • *
  • Posts: 70
Re: MySSQL
« Reply #14 on: July 27, 2009, 09:16:09 am »
Then it shouldn't be in the name.

Offline jrgp

  • Administrator
  • Flamebow Warrior
  • *****
  • Posts: 5037
Re: MySSQL
« Reply #15 on: July 27, 2009, 10:03:01 am »
Then it shouldn't be in the name.
Correct, as he just took the name to be cool, which is annoying and misleading as hell since the code and usage bares absolutely no resemblance to Structured Query Language whatsoever.

Fortunately, in one of the next server releases eC has promised to support SQLITE support, which will render this abomination deprecated.
« Last Edit: July 27, 2009, 10:04:46 am by jrgp »
There are other worlds than these

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: MySSQL
« Reply #16 on: July 27, 2009, 03:05:51 pm »
Fortunately, 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.

Offline jrgp

  • Administrator
  • Flamebow Warrior
  • *****
  • Posts: 5037
Re: MySSQL
« Reply #17 on: July 27, 2009, 03:34:23 pm »
Fortunately, 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.
There are other worlds than these

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: MySSQL
« Reply #18 on: July 27, 2009, 04:28:23 pm »
Not 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?

Offline jrgp

  • Administrator
  • Flamebow Warrior
  • *****
  • Posts: 5037
Re: MySSQL
« Reply #19 on: July 27, 2009, 04:58:51 pm »
Not 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?
The file _is_ the database.

Quote
SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine.
There are other worlds than these