library IADO;
uses
SysUtils,
DB,
ADODB,
dbclient,
Provider,
activex;
Tobj = class
private
ADOConnection1: TADOConnection;
Q1: TADOQuery;
Q2: TADOQuery;
// CDS1: TClientDataSet;
DSP1: TDataSetProvider;
public
constructor CREATE();
destructor DESTROY;
override;
procedure OPENSQL(S: pchar);
procedure EXECSQL(S: string);
function GFI(S: string): INTEGER;
function GFS(S: pchar): pchar;
function savedat(dat: olevariant;
sTable: pchar): integer;
end;
var obj: Tobj;
function GETPYM(CH: pchar): pchar;
stdcall;
external 'imsg.dll' name 'getpym';
function GETSQLCONSTR(): PCHAR;
stdcall;
external 'imsg.dll' name 'getsqlconstr';
procedure msg(s: PCHAR);
stdcall;
external 'imsg.dll' name 'msg';
//procedure writefile(sF
char;s
char);STDCALL;external 'IWriteFile.dll' name 'writefile';
function GETINIkey(IniFile: PCHAR;
MAINKEY: PCHAR;
SUBKEY: PCHAR): PCHAR;
stdcall;
external 'imsg.dll' name 'getinikey';
function TOBJ.GFI(S: string): INTEGER;
begin
if Q1.FIELDBYNAME(S).IsNull then
RESULT := 0
else
RESULT := Q1.FIELDBYNAME(S).ASINTEGER;
end;
function TOBJ.GFS(S: pchar): pchar;
begin
getmem(result, length(Q1.FIELDBYNAME(S).asstring) + 1);
if Q1.FIELDBYNAME(S).IsNull then
RESULT := ''
else
strcopy(RESULT, pchar(Q1.FIELDBYNAME(S).asstring));
end;
procedure TOBJ.OPENSQL(S: pchar);
begin
Q1.Close;
Q1.SQL.Clear;
Q1.SQL.Add(S);
Q1.Open;
end;
procedure TOBJ.EXECSQL(S: string);
begin
Q1.Close;
Q1.SQL.Clear;
Q1.SQL.Add(S);
Q1.ExecSQL;
end;
function isPrivate(lid: integer;
lPRIVILAGE: pchar): integer;
stdcall;
var sq: string;
begin
if obj = nil then
obj := Tobj.CREATE();
sq := 'select sp.被选择 FROM T_STAFF_PRIVILAGE sp,t_operator o,T_PRIVILAGE p ';
sq := sq + 'where o.i_id=' + inttostr(lID);
sq := sq + ' and p.名称=' + chr(39) + lPRIVILAGE + chr(39);
sq := sq + ' and o.角色ID=sp.角色ID';
sq := sq + ' and sp.权限ID=p.i_ID';
obj.OPENSQL(pchar(Sq));
if obj.q1.Eof then
begin
result := -1;
// '开发者,没有为' + s_privilige + '配角色、权力!!';
exit
end;
result := 0;
if obj.q1.fieldbyname('被选择').AsBoolean then
result := 1
end;
function getdat(lmainSQL: pchar): olevariant;
stdcall;
begin
if obj = nil then
begin
obj := Tobj.CREATE();
end;
obj.openSQL(lmainSQL);
result := OBJ.DSP1.DATA;
// obj.Free;
end;
function tobj.savedat(dat: olevariant;
sTable: pchar): integer;
var iErr: integer;
begin
// opensql('select * from '+sTable);
dsp1.ApplyUpdates(Dat, 0, iErr);
// dsp1.ResolveToDataSet:=true;
result := iErr;
end;
function savedat(sTable: pchar;
dat: olevariant): integer;
stdcall;
//var obj: Tobj;
begin
if obj = nil then
obj := Tobj.CREATE();
result := obj.savedat(Dat, sTable);
// obj.Free;
end;
function iseof(lmainSQL: pchar): boolean;
stdcall;
begin
result := true;
if obj = nil then
obj := Tobj.CREATE();
obj.OpenSQL(lmainSQL);
if not obj.q1.Eof then
result := false;
end;
procedure nEXECSQL(lmainSQL: pchar);
stdcall;
begin
if obj = nil then
obj := Tobj.CREATE();
obj.EXECSQL(lmainSQL);
end;
function GetID(lmainSQL: pchar): INTEGER;
stdcall;
begin
//这个函数是有要求的 select i_id as id
result := 0;
if obj = nil then
obj := Tobj.CREATE();
obj.OpenSQL(lmainSQL);
if not obj.q1.Eof then
result := OBJ.gfi('ID');
end;
function GetfI(lmainsql: pchar;
lfieldname: pchar): INTEGER;
stdcall;
begin
result := 0;
if obj = nil then
obj := Tobj.CREATE();
obj.OpenSQL(lmainSQL);
if not obj.q1.Eof then
result := OBJ.gfi(lfieldname);
end;
function Getfs(lmainsql: pchar;
lfieldname: pchar): pchar;
stdcall;
var s: string;
p: pchar;
begin
if obj = nil then
obj := Tobj.CREATE();
obj.OpenSQL(lmainSQL);
s := obj.Q1.FieldByName(lfieldname).AsString;
GetMem(result, length(s) + 1);
if not obj.q1.Eof then
strcopy(result, pchar(s))
else
strcopy(result, '');
end;
procedure init_date(var m: tmydate);
stdcall;
var s: string;
begin
if obj = nil then
obj := Tobj.CREATE();
s := ' select * from VIEW_Init_Date';
obj.OpenSQL('select * from VIEW_Init_Date');
m.today := obj.GFS('today');
m.tormorrow := obj.GFS('tormorrow');
m.yestoday := obj.GFS('yestoday');
m.thismonthfirstday := obj.GFS('thismonthfirstday');
m.thismonthlastday := obj.GFS('thismonthlastday');
m.nextmonthFirstday := obj.GFS('nextmonthFirstday');
m.YearFirstday := obj.GFS('YearFirstday');
end;
procedure auto_rebrush_py_code(
ltable: pchar;
lidField: pchar;
lfield: pchar;
lpyfield: pchar);
stdcall;
var s: string;
p: pchar;
begin
if obj = nil then
obj := Tobj.CREATE();
s := ' select ' + lidfield + ',' + lfield + ' from ' + ltable;
obj.OpenSQL(pchar(s));
while not obj.Q1.Eofdo
begin
s := obj.gfs(lfield);
if s <> '' then
begin
p := GETPYM(pchar(s));
s := 'update ' + ltable + ' set ' + lpyfield + '=' + chr(39) + p + chr(39) + ' where ' + lidfield + '=' + obj.GFS(lidfield);
obj.Q2.Close;
obj.Q2.SQL.Clear;
obj.Q2.SQL.Add(S);
obj.Q2.ExecSQL;
end;
obj.Q1.Next
end;
end;
constructor Tobj.CREATE();
begin
CoInitialize(nil);
ADOConnection1 := TADOConnection.Create(nil);
ADOConnection1.ConnectED := FALSE;
ADOConnection1.LoginPrompt := FALSE;
// ADOConnection1.ConnectionString :='Provider=SQLOLEDB.1;Persist Security Info=False;User ID=SA;Initial Catalog=PM;Data Source=.';// 聊天server 无法读出文件! getsqlconstr();
// ADOConnection1.ConnectionString := getsqlconstr();
ADOConnection1.ConnectionString := getinikey('./NetUpdate.ini', '连接', 'constr');
Q1 := TADOQuery.Create(nil);
Q1.Connection := ADOConnection1;
Q2 := TADOQuery.Create(nil);
Q2.Connection := ADOConnection1;
DSP1 := TDataSetProvider.Create(nil);
DSP1.DataSet := Q1;
dsp1.Options := [poAllowMultiRecordUpdates];
// CDS1:= TClientDataSet.Create(NIL);
// CDS1.ProviderName :=DSP1;
if not ADOConnection1.Connected then
begin
ADOConnection1.Connected := TRUE;
end;
end;
destructor Tobj.DESTROY;
begin
couninitialize;
//coInitialize;
FreeAndNil(DSP1);
FreeAndNil(Q1);
FreeAndNil(Q2);
ADOConnection1.Connected:=false;
FreeAndNil(ADOConnection1);
// Initialize;
inherited;
end;
procedure CloseDBLink();
stdcall;
begin
if OBJ <> nil then
OBJ.Free;
end;
{$R *.res}
exports
getdat name 'getdat',
iseof name 'iseof',
getid name 'getid',
GetFI name 'getfi',
GetFS name 'getfs',
savedat name 'savedat',
CloseDBLink name 'closedblink',
isPrivate name 'isprivate',
nexecsql name 'nexecsql',
init_date name 'init_date',
auto_rebrush_py_code name 'auto_rebrush_py_code';
begin
end.