unit i_SYSPALVL;

interface

uses
   DB, DBTables, Sysutils, { Variants, } i_ebss;

type
   _SYSPALVL = class(_ebss)
   public
      function getAllRows(tmpSessionName, tmpDatabaseName: String):TQuery;overload;
      function getAllRows(tmpSessionName, tmpDatabaseName, Cond:String):TQuery;overload;

      function getSomeColumns(tmpSessionName, tmpDatabaseName, ColumnNames:String):TQuery;overload;
      function getSomeColumns(tmpSessionName, tmpDatabaseName, ColumnNames, Cond:String):TQuery;overload;
      function setSomeColumns(tmpSessionName, tmpDatabaseName: String;FieldNames, Values: Variant) :Boolean;

      function Insert(tmpSessionName, tmpDatabaseName:String;Values: Variant):Boolean;
      function Delete(tmpSessionName, tmpDatabaseName, Cond:String):Boolean;
      function Empty(tmpSessionName, tmpDatabaseName: String):Boolean;

      function getSLEVELs(tmpSessionName, tmpDatabaseName: String):TQuery;overload;
      function getSLEVELs(tmpSessionName, tmpDatabaseName, Cond:String):TQuery;overload;
      function getSLEVEL(tmpSessionName, tmpDatabaseName, Cond:String):TField;overload;
      function getSLEVELvalue(tmpSessionName, tmpDatabaseName, Cond:String):Real;overload;
      function setSLEVELvalue(tmpSessionName, tmpDatabaseName:String; Value:String; Cond:String):Boolean;

      function getREMARKSs(tmpSessionName, tmpDatabaseName: String):TQuery;overload;
      function getREMARKSs(tmpSessionName, tmpDatabaseName, Cond:String):TQuery;overload;
      function getREMARKS(tmpSessionName, tmpDatabaseName, Cond:String):TField;overload;
      function getREMARKSvalue(tmpSessionName, tmpDatabaseName, Cond:String):String;overload;
      function setREMARKSvalue(tmpSessionName, tmpDatabaseName:String; Value:String; Cond:String):Boolean;
   end;

var
   admin_SYSPALVL: _SYSPALVL;

implementation

function _SYSPALVL.getAllRows(tmpSessionName, tmpDatabaseName: String):TQuery;
begin
   Result := openSQL(tmpSessionName, tmpDatabaseName, Format('Select * from %s', ['SYSPALVL']));
end;

function _SYSPALVL.getAllRows(tmpSessionName, tmpDatabaseName, Cond:String):TQuery;
begin
   Result := openSQL(tmpSessionName, tmpDatabaseName, Format('Select * from %s where %s',['SYSPALVL', Cond]));
end;

function _SYSPALVL.getSomeColumns(tmpSessionName, tmpDatabaseName, ColumnNames:String):TQuery;
begin
   Result := openSQL(tmpSessionName, tmpDatabaseName, Format('Select %s from %s',[ColumnNames, 'SYSPALVL']));
end;

function _SYSPALVL.getSomeColumns(tmpSessionName, tmpDatabaseName, ColumnNames, Cond:String):TQuery;
begin
   Result := openSQL(tmpSessionName, tmpDatabaseName, Format('Select %s from %s where %s',[ColumnNames, 'SYSPALVL', Cond]));
end;

function _SYSPALVL.setSomeColumns(tmpSessionName, tmpDatabaseName: String;FieldNames, Values: Variant) :Boolean;
var
   i,n: Integer;
   NamesCount, ValuesCount:Integer;
   tmpSQL: String;
begin
   Result := False;

   NamesCount := VarArrayHighBound(FieldNames, 1);
   ValuesCount := VarArrayHighBound(Values, 1);

   If NamesCount = ValuesCount then
   begin
      n := NamesCount;

      tmpSQL := Format('Update %s set ',['SYSPALVL']);

      For i:= 0 to n do
      begin
         tmpSQL := tmpSQL + Format('%s = %s',[FieldNames[i], Values[i]]);
         If i < n then
         begin
            tmpSQL := tmpSQL +', ';
         end;
      end;
      Result := execSQL(tmpSessionName, tmpDatabaseName, tmpSQL);
   end;
end;

function _SYSPALVL.Insert(tmpSessionName, tmpDatabaseName: String;Values: Variant):Boolean;
var
   i,n: Integer;
   ValueCount: Integer;
   tmpSQL: String;
begin
   Result := False;

   ValueCount := VarArrayHighBound(Values, 1);

   If ValueCount > 0 then
   begin
      n := ValueCount;

      tmpSQL := Format('Insert into %s values(',['SYSPALVL']);

      For i:= 0 to n do
      begin
         tmpSQL := tmpSQL + Format('%s',[Values[i]]);
         If i < n then
         begin
            tmpSQL := tmpSQL +', ';
         end;
      end;
      tmpSQL := tmpSQL + ')';

      Result := execSQL(tmpSessionName, tmpDatabaseName, tmpSQL);
   end;
end;

function _SYSPALVL.Delete(tmpSessionName, tmpDatabaseName, Cond:String):Boolean;
begin
   Result := execSQL(tmpSessionName, tmpDatabaseName, Format('Delete from %s where %s',['SYSPALVL', Cond]));
end;

function _SYSPALVL.Empty(tmpSessionName, tmpDatabaseName: String):Boolean;
begin
   Result := execSQL(tmpSessionName, tmpDatabaseName, Format('Delete from %s',['SYSPALVL']));
end;


function _SYSPALVL.getSLEVELs(tmpSessionName, tmpDatabaseName: String):TQuery;
begin
  Result := openSQL(tmpSessionName, tmpDatabaseName, Format('Select SLEVEL from %s',['SYSPALVL']));
end;

function _SYSPALVL.getSLEVELs(tmpSessionName, tmpDatabaseName, Cond:String):TQuery;
begin
  Result := openSQL(tmpSessionName, tmpDatabaseName, Format('Select SLEVEL from %s where %s',['SYSPALVL', Cond]));
end;

function _SYSPALVL.getSLEVEL(tmpSessionName, tmpDatabaseName, Cond:String):TField;
var
  Query: TQuery;
begin
  Result := nil;

  Query := getSLEVELs(tmpSessionName, tmpDatabaseName, Cond);
  If Not Query.IsEmpty then
  begin
    Result := Query.FieldByName('SLEVEL');
  end;
  Query.Free;
end;

function _SYSPALVL.getSLEVELvalue(tmpSessionName, tmpDatabaseName, Cond:String):Real;
var
  Query: TQuery;
begin
  Result := -1;

  Query := getSLEVELs(tmpSessionName, tmpDatabaseName, Cond);
  If Not Query.IsEmpty then
  begin
    Result := Query.FieldByName('SLEVEL').AsVariant;
  end;
  Query.Free;
end;

function _SYSPALVL.setSLEVELvalue(tmpSessionName, tmpDatabaseName: String; Value:String; Cond:String):Boolean;
begin
  Result := execSQL(tmpSessionName, tmpDatabaseName, Format('Update %s set SLEVEL = %s where %s',
                           ['SYSPALVL', Value, Cond])
                   );
end;

function _SYSPALVL.getREMARKSs(tmpSessionName, tmpDatabaseName: String):TQuery;
begin
  Result := openSQL(tmpSessionName, tmpDatabaseName, Format('Select REMARKS from %s',['SYSPALVL']));
end;

function _SYSPALVL.getREMARKSs(tmpSessionName, tmpDatabaseName, Cond:String):TQuery;
begin
  Result := openSQL(tmpSessionName, tmpDatabaseName, Format('Select REMARKS from %s where %s',['SYSPALVL', Cond]));
end;

function _SYSPALVL.getREMARKS(tmpSessionName, tmpDatabaseName, Cond:String):TField;
var
  Query: TQuery;
begin
  Result := nil;

  Query := getREMARKSs(tmpSessionName, tmpDatabaseName, Cond);
  If Not Query.IsEmpty then
  begin
    Result := Query.FieldByName('REMARKS');
  end;
  Query.Free;
end;

function _SYSPALVL.getREMARKSvalue(tmpSessionName, tmpDatabaseName, Cond:String):String;
var
  Query: TQuery;
begin
  Result := 'null';

  Query := getREMARKSs(tmpSessionName, tmpDatabaseName, Cond);
  If Not Query.IsEmpty then
  begin
    Result := Query.FieldByName('REMARKS').AsString;
  end;
  Query.Free;
end;

function _SYSPALVL.setREMARKSvalue(tmpSessionName, tmpDatabaseName: String; Value:String; Cond:String):Boolean;
begin
  Result := execSQL(tmpSessionName, tmpDatabaseName, Format('Update %s set REMARKS = %s where %s',
                           ['SYSPALVL', Value, Cond])
                   );
end;
end.
