通用的咏南数据序列、还原类
通用的咏南数据序列、还原类
1)支持DELPHI7及以上版本,更低DELPHI版本没有测试,理论上也支持
2)跨平台:支持WIN32,WIN64,LINUX,MACOS,安卓、IOS
3)支持所有的DELPHI SOCKET控件
4)支持STRING、INTEGER、DATATIME、BOOLEAN等基本数据类型的序列和还原
5)支持文件、流、数据集、BUFFER、结构体等复杂数据类型的序列和还原
6)支持多数据集的序列和还原
下面演示如何使用。
1)DATASNAP演示
function TServerMethods1.Query99(const accountNo, sql: string): string; var d: TfrmDB; pool: TDBPool; serial: TynSerial; begin Result := null; if (accountNo = '') or (sql = '') then Exit; pool := GetDBPool(accountNo); if not Assigned(pool) then Exit; d := pool.Lock; if not Assigned(d) then Exit; serial:= TynSerial.Create; try try SetTraceOn(d); d.qryOpen.Close; d.qryOpen.sql.Clear; d.qryOpen.sql.Text := sql; d.qryOpen.Open(); serial.WriteFDDataSet(d.qryOpen); serial.WriteString('str', 'test'); serial.WriteDateTime('time', Now); serial.WriteOleVariant('ole', d.dsp.Data); Result := serial.Text; except on e: Exception do begin Result := null; Log.WriteLog('TServerMethods1.QuerySql ' + e.Message); end; end; finally d.qryOpen.Close; pool.Unlock(d); serial.Free; SetTraceOff(d); end; end;
2)MORMOT演示
class function Tmymethod.querys2(const str: string): string; // clientdataset主从表查询 var pool: TDBPool; dm: TfrmDB; serial: TynSerial; accountno, sql, sql2: string; begin serial := TynSerial.Create; try try serial.Text := str; accountno := serial.ReadString('accountno'); sql := serial.ReadString('sql'); sql2 := serial.ReadString('sql2'); serial.Text := ''; pool := GetDBPool(accountno); dm := pool.Lock; dm.qryOpen.Close; dm.qryOpen.sql.Clear; dm.qryOpen.sql.Add(sql); serial.WriteOleVariant('dataset', dm.dsp.Data); dm.qryOpen.Close; dm.qryOpen.sql.Clear; dm.qryOpen.sql.Add(sql2); serial.WriteOleVariant('dataset2', dm.dsp.Data); Result := serial.Text; except on E: Exception do begin Result := ''; Log.WriteLog('Tmymethod.querys ' + E.Message); end; end; finally pool.unlock(dm); serial.Free; end; end;
3)CROSS SOCKET演示
function TynFiredac.QuerySQL(const ASQL: string): string; var serial: TynSerial; begin Result := ''; if ASQL = '' then Exit; serial := TynSerial.Create; try try FDQuery1.Close; FDQuery1.SQL.Clear; FDQuery1.SQL.Add(ASQL); FDQuery1.Open; serial.WriteFDDataSet('dataset', FDQuery1); Result := serial.Text; except on E: Exception do begin Result := ''; Log.WriteLog('TynFiredac.QuerySQL ' + E.Message); end; end; finally FDQuery1.Close; FDConnection1.Close; serial.Free; end; end;
本文来自博客园,作者:{咏南中间件},转载请注明原文链接:https://www.cnblogs.com/hnxxcxg/p/10564002.html