ReadMe

新版本delphi,可以用string类型,旧版本需要用widestring

===========================================

function TFRMSOEDIT.vartosql(value: Variant): wideString;
var
tmp: widestring;
begin
if (varisnull(value)) or (varisempty(value)) then
Result := 'NULL'
else
case Vartype(value) of
varDate:
begin
tmp := formatDatetime('yyyy-mm-dd hh:mm:ss', VartoDatetime(value));
Result := Quotedstr(tmp);
end;
varString, varOlestr:
Result := Quotedstr(Trim(Vartostr(value)));
varboolean:
begin
if value then
Result := '1'
else
Result := '0';
end;
varSmallint, varInteger, varDouble, varShortInt, varInt64, varLongWord, varCurrency:
begin
Result := trim(Vartostr(value));
end;
else
Result := Quotedstr(Trim(Vartostr(value)));
end;
end;

function TFRMSOEDIT.GetCdsDetailSsql(cdsDelta: THxDataSet; TableName, KeyField, vWhere: WideString): WideString;
var
i: integer;
s1, s2: string;
CmdStr: string;
lcds: THxDataSet;
begin
Result := '';
if (not cdsDelta.Active) and (cdsDelta.ChangeCount <= 0) then
Exit;
CmdStr := 'select * from ' + TableName + ' where 1=2';
lcds := THxDataSet.Create(nil);
lcds.Data := cdsDelta.Delta;
for i := 1 to lcds.FieldCount do
if cdsDelta.FindField(lcds.Fields[i - 1].FieldName) <> nil then
cdsDelta.FindField(lcds.Fields[i - 1].FieldName).Tag := 1;
lcds.Close;
if cdsDelta.RecordCount > 0 then
begin
cdsDelta.First;
s1 := '';
s2 := '';
while not cdsDelta.Eof do
begin
CmdStr := '';
case cdsDelta.UpdateStatus of
usUnmodified:
begin
s2 := VarToSql(cdsDelta[KeyField]);
end;
usModified:
begin
s1 := '';
s2 := ' where ' + KeyField + '=' + VarToSql(cdsDelta[KeyField]);
for i := 1 to cdsDelta.FieldCount do
// if (not cdsDelta.Fields[i - 1].IsNull) and (cdsDelta.Fields[i - 1].Tag = 1) then
if (not cdsDelta.Fields[i - 1].IsBlob) and (not VarIsArray(cdsDelta.Fields[i - 1].value)) then
begin
if (cdsDelta.Fields[i - 1].NewValue <> Variants.Unassigned) and (cdsDelta.Fields[i - 1].Tag = 1) and (cdsDelta.Fields[i - 1].OldValue <> cdsDelta.Fields[i - 1].NewValue) then
begin
s1 := s1 + #13#10 + ' update ' + TableName + ' set ' + Trim(cdsDelta.Fields[i - 1].FieldName) + ' = ' + VarToSql(cdsDelta.Fields[i - 1].NewValue) + s2;

end;
end;
CmdStr := s1;
end;
usInserted:
begin
s1 := '';
s2 := '';
for i := 1 to cdsDelta.FieldCount do
if not cdsDelta.Fields[i - 1].IsBlob then
if (not cdsDelta.Fields[i - 1].IsNull) and (cdsDelta.Fields[i - 1].Tag = 1) then
begin
if s1 = '' then
begin
s1 := Trim(cdsDelta.Fields[i - 1].FieldName);
s2 := VarToSql(cdsDelta.Fields[i - 1].value);
end
else
begin
s1 := s1 + ',' + Trim(cdsDelta.Fields[i - 1].FieldName);
s2 := s2 + ',' + VarToSql(cdsDelta.Fields[i - 1].value);
end;
end;
if s1 <> '' then
begin
CmdStr := 'insert into ' + TableName + '(' + s1 + ') Values (' + s2 + ')';
end;
end;
usDeleted:
begin
s2 := VarToSql(cdsDelta[KeyField]);
CmdStr := 'delete from ' + TableName + ' Where ' + KeyField + ' = ' + s2;
end;
end;
Result := Result + CmdStr + #13#10;
cdsDelta.Next;
end;
end;
FreeAndNil(lcds);
end;

最新文章

  1. 《Qt Quick 4小时入门》学习笔记4
  2. 在CentOS上安装并运行SparkR
  3. centos 命令集合
  4. 网络爬虫3-使用LIB_http库
  5. 如何在命令行模式下查看Python帮助文档---dir、help、__doc__
  6. android 启动第三方程序的代码
  7. cf472D Design Tutorial: Inverse the Problem
  8. MySQL 复制
  9. Jquery CSS 与 Attr
  10. [USACO09MAR]地震损失2Earthquake Damage 2
  11. adb命令集合
  12. 前端-JavaScript1-4——JavaScript之变量
  13. English trip EM2-LP-1A Hi Teacher:Taylor
  14. BP神经网络的理论理论常识
  15. 人生苦短之我用Python篇(socket编程)
  16. virtual memory exhausted: Cannot allocate memory 解决方法
  17. 教你用 jVectorMap 制作属于自己的旅行足迹
  18. Java使用POI导出excel(下)——实例与小技巧
  19. Spartan-6 FPGA Configuration
  20. 使用ASP.NET 的缓存机制的示例

热门文章

  1. 洛谷P1073最优贸易(跑两遍dij)
  2. docker+hexo 搭建博客
  3. html5或者移动端暴力定位城市-高德地图,可以取到当前的城市code,亲测好用
  4. dp求解各种子串子序列
  5. STM32F4/F7运算性能
  6. 【PAT甲级】1063 Set Similarity (25 分)
  7. Java入门笔记 02-数组
  8. 第四周之Hadoop学习(四)
  9. vs2010 c++中内嵌汇编代码
  10. Java面向对象编程 -1