没想到delphi DBXXXX居然这样子得到recordCount 偶尔看源代码,发现TSQLCustomDataSet.RecordCount是用 select count(*) from xxx 查出来的.为何要再查一下,虽然是单向的,抓来的数据放哪了?不能直接得到记录数吗?顺便散分 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 TSQLxxx是不是bde的那一套?这样做,是不是因为取记录是分批背景取的?所以无法根据已经取得的记录数立即得到recordcount 上源代码function GetRows(Query: string; Connection: TSQLConnection): Integer;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 Delphi 多线程使用数组动态创建 ADOQuery1.Parameters.ParamByName('a')中的参数a问题 在RAVE中如何显示表中字段中保存的JPG格式的图片? 新起點, 新開始,女孩子願意做程序的可以過來看看.^_^ 问:如何写一个延时程序,望有代码!在线等,急! 怎么捕捉EDatabaseError异常。 菜鸟问的问题都很简单快来拿分呀 使用过Rave报表的进来坐坐! 50分,请问在企业 管理器建立了a表,现在在查询分析器新增一个字段,怎样写 如何取treeview 父结点 ID 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