偶尔看源代码,发现TSQLCustomDataSet.RecordCount是用 select count(*) from xxx 查出来的.
为何要再查一下,虽然是单向的,抓来的数据放哪了?不能直接得到记录数吗?
顺便散分
为何要再查一下,虽然是单向的,抓来的数据放哪了?不能直接得到记录数吗?
顺便散分
解决方案 »
- 图片存储的问题
- 请教:一个报错,谁帮忙看看????
- 广域网的三层结构的软件,使用TCP协议还是UDP协议好?
- 关于事务
- 请问本地access库的数据如何传到远程的sql server上
- 请教用delphi开发数据库接口的思路
- delphi 2009 webservice返回olevariant(clientdataset.data)
- 如何在程序运行中获得当前系统中dao的版本
- 请问怎样获取内部网上服务器或其他机上的系统目录(如:\\Server\C\winnt\system32,又或 \\CompterName\D\Windows\System)?
- pascal中怎样处理文本文件的输入换行
- delphi随机函数
- 问个小数点位移的问题,请帮忙看下怎么解决!
这样做,是不是因为取记录是分批背景取的?所以无法根据已经取得的记录数立即得到recordcount
var
DS: TSQLDataSet;
begin
Result := -1;
DS := TSQLDataSet.Create(nil);
try
DS.SQLConnection := Connection;
DS.CommandText := Query;
DS.Active := True;
if not DS.EOF then
Result := DS.Fields[0].AsInteger;
finally
DS.Free;
if Result = -1 then
DatabaseError(SNotSupported);
end;
end;function TCustomSQLDataSet.GetRecordCount: Integer;
const
SDistinct = ' distinct '; { do not localize }
SSelectCount = 'select count(*) from '; { do not localize }
var
TableName, Query: string;
HoldPos: Integer;
begin
if FRecords <> -1 then
Result := FRecords
else
begin
CheckConnection(eConnect);
if Self.CommandText = '' then
DatabaseError(SNoSQLStatement);
case CommandType of
ctServerMethod,
ctStoredProc:
DatabaseError(SNotSupported);
ctTable:
begin
with GetInternalConnection.FDBXConnection do
begin
//Query := 'select count(*) from ' + GetQuoteChar + FCommandText + GetQuoteChar;
Query := 'select count(*) from ' + QuoteIdentifier(CommandText, false);
end;
end;
ctQuery:
begin
TableName := GetTableNameFromSQLEx(FCommandText, GetIdOption(FSQLConnection));
if (TableName = '') or (Params.Count > 0) then
DatabaseError(SNotSupported);
if Pos(SDistinct, LowerCase(FCommandText)) = 0 then
Query := SSelectCount
else
DatabaseError(SNotSupported);
HoldPos := Pos(SWhere, LowerCase(FCommandText));
if HoldPos = 0 then
Query := Query + GetQuoteChar + TableName + GetQuoteChar
else begin
Query := Query + GetQuoteChar + TableName + GetQuoteChar + copy(FCommandText, HoldPos, Length(FCommandText) - (HoldPos-1));
HoldPos := Pos(sOrderBy, LowerCase(Query));
if HoldPos > 0 then
Query := copy(Query, 1, HoldPos - 1);
end;
end;
end;
FRecords := GetRows(Query, FSQLConnection); //这行看上面
Result := FRecords;
end;
end;
应该是这样
TCustomSQLDataSet
而不是
TSQLCustomDataSet