📄 dbfuncs.pas
字号:
if use_ado then ParamVariant(s, v)
else bde_query.ParamByName(s).AsFloat:=v;
end;
procedure TPodmsQuery.Open;
begin
if use_ado then ado_query.Open
else bde_query.Open;
end;
procedure TPodmsQuery.Close;
begin
if use_ado then ado_query.Close
else bde_query.Close;
end;
procedure TPodmsQuery.ExecSQL;
begin
if use_ado then ado_query.ExecSQL
else bde_query.ExecSQL;
end;
procedure TPodmsQuery.Next;
begin
if use_ado then ado_query.Next
else bde_query.Next;
end;
procedure TPodmsQuery.Last;
begin
if use_ado then ado_query.Last
else bde_query.Last;
end;
procedure TPodmsQuery.First;
begin
if use_ado then ado_query.Last
else bde_query.Last;
end;
procedure TPodmsQuery.Insert;
begin
if use_ado then ado_query.Insert
else bde_query.Insert;
end;
procedure TPodmsQuery.Post;
begin
if use_ado then ado_query.Post
else bde_query.Post;
end;
function TPodmsQuery.Locate(const KeyFields: String; const KeyValues: Variant; Options: TLocateOptions
): Boolean;
begin
if use_ado then result:=ado_query.Locate(keyFields,KeyValues,Options)
else result:=bde_query.Locate(keyFields,KeyValues,Options);
end;
procedure TPodmsQuery.Edit;
begin
if use_ado then ado_query.Edit
else bde_query.Edit;
end;
function TPodmsQuery.RecordCount: Integer;
begin
if use_ado then Result:=ado_query.RecordCount
else Result:=bde_query.RecordCount;
end;
function TPodmsQuery.RowsAffected: Integer;
begin
if use_ado then Result:=ado_query.RowsAffected
else Result:=bde_query.RowsAffected;
end;
function TPodmsQuery.ParamsCount: Integer;
begin
if use_ado then Result:=ado_query.Parameters.Count
else Result:=bde_query.Params.Count;
end;
function TPodmsQuery.ParamName(p: Integer): String;
begin
if use_ado then Result:=ado_query.Parameters.Items[p].Name
else Result:=bde_query.Params.Items[p].Name;
end;
function TPodmsQuery.ParamDataType(p: Integer): TFieldType;
begin
if use_ado then Result:=ado_query.Parameters.Items[p].DataType
else Result:=bde_query.Params.Items[p].DataType;
end;
function TPodmsQuery.ParamIsNull(p: Integer): Boolean;
begin
if use_ado then Result:=VarIsNull(ado_query.Parameters.Items[p].Value)
else Result:=bde_query.Params.Items[p].IsNull;
end;
function TPodmsQuery.Fields:Tfields;
begin
if use_ado then Result:=ado_query.Fields
else Result:=bde_query.Fields;
end;
function TPodmsQuery.FieldbyName(const FieldName:string):Tfield;
begin
if use_ado then Result:=ado_query.FieldByName(FieldName)
else Result:=bde_query.FieldByName(FieldName);
end;
function TPodmsQuery.ParamText(p: Integer): String;
begin
if use_ado then Result:=ado_query.Parameters.Items[p].Value
else Result:=bde_query.Params.Items[p].Text;
end;
function TPodmsQuery.ColumnValue(const column: String): Variant;
begin
if use_ado then Result:=ado_query[column]
else Result:=bde_query[column];
end;
function TPodmsQuery.SQLtostr:TStrings;
begin
if use_ado then Result:=ado_query.SQL
else Result:=bde_query.SQL;
end;
procedure TPodmsQuery.Prior;
begin
if use_ado then ado_query.Prior
else bde_query.Prior;
end;
procedure TPodmsQuery.Refresh;
begin
if use_ado then ado_query.Refresh
else bde_query.Refresh;
end;
procedure TPodmsQuery.InsertRecord(const Values: array of const);
begin
if use_ado then ado_query.InsertRecord(Values)
else bde_query.InsertRecord(Values);
end;
function TPodmsQuery.MoveBy(Distance: Integer): Integer;
begin
if use_ado then Result:=ado_query.MoveBy(Distance)
else Result:=bde_query.MoveBy(Distance);
end;
//
// When retrieving a date value from the database server, it is possible
// that it may be NULL. If it is NULL then var:=q['date_row'] will
// fail because NULL is not a valid date & time value. To avoid this use
// this function. For example:
//
// var:=SafeDate(q['DATE_ROW']);
// var:=SafeDate(q['ANOTHER_DATE_ROW'], UTCNow);
//
// Args: variant value from database
// optional default date & time to use if NULL
//
// Returns: correct variant value to use
//
function SafeDate(date_time: Variant; use_default: TDateTime): Variant;
begin
if VarIsNull(date_time) then begin
if use_default=0.0 then Result:=Null
else Result:=use_default
end else begin
Result:=date_time;
end;
end;
//
// When retrieving a boolean value from the database server, it is possible
// that it may infact be a CHAR(1) and not a BIT/BOOLEAN data type. This is
// because some RDBMS systems do not support the BIT/BOOLEAN type. This
// function will convert 'Y' to TRUE and 'N' to FALSE if the RDBMS does not
// support the BIT type.
//
// Args: variant value from database
//
// Returns: TRUE or FLASE
//
function MakeBoolean(value: Variant): WordBool;
begin
if (VarIsNull(value)) then Result:=FALSE
else if value='Y' then Result:=TRUE
else Result:=FALSE;
end;
//
// Returns TRUE if BDE is insalled
//
function IsBDEInstalled: Boolean;
var Ini:TRegIniFile;
sect:string;
begin
// Initialise
ini:=nil;
Result:=FALSE;
// Open registry
try
Ini:=TRegIniFile.Create(BDE_REGSECTION);
Ini.RootKey:=HKEY_LOCAL_MACHINE;
sect:=BDE_REGSECTION;
if ini.ReadString(sect, 'DLLPATH', '')<>'' then Result:=TRUE;
except
// Ignore
end;
// Done
if ini<>nil then ini.Free;
end;
//
// Returns TRUE if ADO is insalled
//
function IsADOInstalled: Boolean;
var Ini:TRegIniFile;
sect:string;
begin
// Initialise
ini:=nil;
Result:=FALSE;
// Open registry
try
Ini:=TRegIniFile.Create(ADO_REGSECTION);
Ini.RootKey:=HKEY_LOCAL_MACHINE;
sect:=ADO_REGSECTION;
if ini.ReadString(sect, 'Version', '')<>'' then Result:=TRUE;
except
// Ignore
end;
// Done
if ini<>nil then ini.Free;
end;
//
// Fill a combo-box window control with a list of all the
// BDE aliases defined
//
// Args: combo-box to fill with values (will be cleared, even on error)
//
// Returns: number of items put into box
// <0 on error
//
function FillComboBoxWithBDE(var combo_box: TComboBox): Integer;
begin
// Initialise
Result:= -1;
combo_box.Items.Clear;
// BDE installed?
if not IsBDEInstalled then Exit;
session.GetDatabaseNames(combo_box.Items);
Result:=combo_box.Items.Count;
end;
//
// Fill a combo-box window control with a list of all the ADO providers
//
// Args: combo-box to fill with values (will be cleared, even on error)
//
// Returns: number of items put into box
// <0 on error
//
function FillComboBoxWithADO(var combo_box: TComboBox): Integer;
begin
// Initialise
Result:= -1;
combo_box.Items.Clear;
// ADO installed?
if not IsADOInstalled then Exit;
// Get the list
GetProviderNames(combo_box.Items);
Result:=combo_box.Items.Count;
end;
//
// Returns TRUE if a BDE alias is using ODBC,
// else it must be a BDE/SQL-Links driver
//
function IsODBCDriver(const AliasName: String): Boolean;
var DriverName: String;
begin
// BDE installed?
if not IsBDEInstalled then begin
Result:=FALSE;
Exit;
end;
// Assume it is ODBC
Result:=TRUE;
DriverName:=Session.GetAliasDriverName(AliasName);
// Is it BDE/SQL-Links?
if DriverName='STANDARD' then Result:=FALSE
else if DriverName='DB2' then Result:=FALSE
else if DriverName='INFORMIX' then Result:=FALSE
else if DriverName='INTRBASE' then Result:=FALSE
else if DriverName='MSACCESS' then Result:=FALSE
else if DriverName='MSSQL' then Result:=FALSE
else if DriverName='ORACLE' then Result:=FALSE
else if DriverName='SYBASE' then Result:=FALSE;
end;
{
//
// A DEBUG function that returns the SQL statement as it would be
// passed to the database, i.e. parameters are filled in
//
function DumpSQL(query: TPodmsQuery): String;
var str: Integer;
begin
// Initialise
Result:='';
if query=nil then Exit;
// Optional SQL statement & parameters
for str:=0 to query.SQL.Count - 1 do
Result:=Result + query.SQL.Strings[str] + #13;
// Parameters
for str:=0 to query.Params.Count - 1 do begin
Result:=Result + query.Params.Items[str].Name+'=';
Result:=Result + query.Params.Items[str].Text;
end;
end;
}
//==============================================================================
//
// BDE functions
//
//
// This functions provides the date, time, or date & time depending
// upon what is asked for and what the database supports. What is ultimtely
// used depends upon the value of DB_DT_USES.
//
// For example, Microsoft SQL Server supports the combined date & time
// data type whereas some others do not and so have a date type and a time type
// but not a combined date & time type. This function will supply either the
// date, time, or date & time depending upon what the database supports and
// what is requested.
//
// For example, GiveDateOrTime(q, 'vcreate_date', DT_DATE, UTCNow) will supply
// only the date (the date & time for combined date & time databases)
//
// For example, GiveDateOrTime(q, 'vcreate_date', DT_TIME, UTCNow) will supply
// only the time (the date & time for combined date & time databases)
//
// For example, GiveDateOrTime(q, 'vcreate_date', DT_TIMETIME, UTCNow) will
// supply the date & time for the parameter on SQL Server whereas the same call
// will fail on some databases because the type is not supported.
//
// Args: query to use
// parameter name of date/time value to fill
// DT_DATE or DT_TIME
// date & time to use
//
// Returns: TRUE on success
//
function GiveDateOrTime(bCombin:boolean;var q: TPodmsQuery; pname: String; give_what: DT_TYPES;
datetime: TDateTime): Boolean;
begin
try
// What does the underlying RDBMS support?
if not bCombin then begin
// Only DATE supported - not a combined date & time type so we need to
// store the date or time depending upon what were asked
case give_what of
DT_DATE: q.ParamDate(pname, Int(datetime));
DT_TIME: q.ParamTime(pname, Frac(datetime));
DT_DATETIME: q.ParamDateTime(pname, datetime);
end;
end else begin
// Supports a combined date & time type, e.g. SQL Server
q.ParamDateTime(pname, datetime);
end;
// Success
Result:=TRUE;
except
// Failed
Result:=FALSE;
end;
end;
//
// Create a new database query
//
// Args: database connection to use
//
// Returns the query object
// nil on exception
//
function CreateNewQuery(const connection: TPodmsConnection): TPodmsQuery;
begin
Result:=nil;
try
Result:=TPodmsQuery.Create(connection);
Result.SQLClear;
except begin
Result.Free;
Raise;
end;
end;
end;
//
// Close a query which was opened via CreateNewQuery
//
procedure CloseNewQuery(var q: TPodmsQuery);
begin
if q=nil then Exit;
q.Free;
q:=nil;
end;
function ConvalOut(val:string;tb,field:string):string;
begin
Result:='';
if tb='CSI_SECU_USER' then begin
if field='C_RIGHTS' then begin
if val='A' then result:='系统用户'
else result:='普通用户';
end;
if field='C_USER_STATUS' then begin
//D-DESABLED A-ACTIVE C-CREATED P-PEDING*/
if val='D' then result:='禁止'
else if val='A' then result:='活动'
else if val='P' then result:='暂停'
end;
end;
end;
function ConvalIn(val:string;tb,field:string):string;
begin
Result:='';
end;
function InsLogs(q:TPodmsQuery):widestring;
var sqlcount:integer;
sqlstrs:widestring;
begin
sqlstrs:='';
showmessage('1');
if q=nil then begin
result:='';
showmessage('2');
exit;
end;
showmessage('3');
for Sqlcount:=0 to q.SQLtostr.Count-1 do begin
sqlstrs:=sqlstrs+q.sqltostr.Strings[ Sqlcount];
end;
showmessage(sqlstrs);
result:=sqlstrs;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -