开发环境:
Delphi7.0,winxp,双核CPU,SqlServer2000的数据库。
dbExpress是7.0自带的。使用TSQLConnection连接数据库,使用TSQLQuery执行sql语句。如下sql语句:
Select T2.LeastPopedom,T2.ByName
,case isnull(T3.LeastPopedom,-2) When -2 Then 0 Else 1 End SelectState
 From TModuleInside T1
 Left Join TInsideInfo T2 On T2.LeastPopedom=T1.LeastPopedom
 Left Join TModuleInsidePopedom T3 On T3.ModuleName=T1.ModuleName
 Left Join TRoles T4 On T4.RolesCode=T3.RolesCode And T4.RolesByName='sdfsaf'
 Where T1.ModuleName='NMeasure'
=======================
If(DM.SQLQ.Active) Then DM.SQLQ.Close;
  DM.SQLQ.SQL.Text:=DD;
  DM.SQLQ.Open;
=========================
这样执行是没有任何问题的。使用TSQLMonitor监测到的执行语句如下:
*******************************************
OLEDB - IDBInitialize
OLEDB - IDBCreateSession
OLEDB - IDBCreateCommand
OLEDB - ICommandText
Select T2.LeastPopedom,T2.ByName,case isnull(T3.LeastPopedom,-2) When -2 Then 0 Else 1 End SelectState From TModuleInside T1 Left Join TInsideInfo T2 On T2.LeastPopedom=T1.LeastPopedom Left Join TModuleInsidePopedom T3 On T3.ModuleName=T1.ModuleName Left Join TRoles T4 On T4.RolesCode=T3.RolesCode And T4.RolesByName='sdfsaf' Where T1.ModuleName='NMeasure'OLEDB - SetCommandText
OLEDB - ICommandPrepare
OLEDB - Prepare
OLEDB - Execute
OLEDB - GetResult
OLEDB - IColumnsInfo
OLEDB - GetColumnInfo
OLEDB - Release
OLEDB - IAccessor
OLEDB - CreateAccessor
OLEDB - GetNextRows
OLEDB - GetData*******************************************然后我要看SQLQ到底有多少记录,引用如下:
If(DM.SQLQ.RecordCount=0) then Begin
    ShowMessage('没有数据');
  End;
然后再次执行,出现如下异常;
dbExpress Error:Operation Not Supported
然后看到TSQLMonitor监测的执行语句如下:
*****************************************
OLEDB - IDBInitialize
OLEDB - IDBCreateSession
OLEDB - IDBCreateCommand
OLEDB - ICommandText
Select T2.LeastPopedom,T2.ByName,case isnull(T3.LeastPopedom,-2) When -2 Then 0 Else 1 End SelectState From TModuleInside T1 Left Join TInsideInfo T2 On T2.LeastPopedom=T1.LeastPopedom Left Join TModuleInsidePopedom T3 On T3.ModuleName=T1.ModuleName Left Join TRoles T4 On T4.RolesCode=T3.RolesCode And T4.RolesByName='sdfsaf' Where T1.ModuleName='NMeasure'OLEDB - SetCommandText
OLEDB - ICommandPrepare
OLEDB - Prepare
OLEDB - Execute
OLEDB - GetResult
OLEDB - IColumnsInfo
OLEDB - GetColumnInfo
OLEDB - Release
OLEDB - IAccessor
OLEDB - CreateAccessor
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ICommandText
select count(*) from "TModuleInside" Where T1.ModuleName='NMeasure'OLEDB - SetCommandText
OLEDB - ICommandPrepare
OLEDB - Prepare
OLEDB - Execute
OLEDB - GetResult
SQL State: 42000, SQL Error Code: 8180SQL State: 42000, SQL Error Code: 107*****************************************为此我做了如下方法,两个方法都能解决这个问题。
1:使用TSqlConnection+TSQLQuery+TDataSetProvider+TClientDataSet然后执行。
2:将sql语句中,不用表的别名,直接用表名。
3:使用eof判断是否有数据,对于如何获得记录总数,就只有采用第1种方法。
问题:一:dbExpressBug的组件中,不支持SQL语句中采取表的别名。
至少我用TSQLQuery和TSQLDataSet都不行。
TSimpleDataSet都不行。
问题二:TSQLQuery获得记录总数的时候,既然还用sql语句到数据库服务器上查询。他就不能从结果集中获得么。
当我用第一个解决方法的时候,监测到执行语句如下:(TClientDataSet是从结果集中获得记录总数的。)
*************************************************************
OLEDB - IDBInitialize
OLEDB - IDBCreateSession
OLEDB - IDBCreateCommand
OLEDB - ICommandText
Select T2.LeastPopedom,T2.ByName,case isnull(T3.LeastPopedom,-2) When -2 Then 0 Else 1 End SelectState From TModuleInside T1 Left Join TInsideInfo T2 On T2.LeastPopedom=T1.LeastPopedom Left Join TModuleInsidePopedom T3 On T3.ModuleName=T1.ModuleName Left Join TRoles T4 On T4.RolesCode=T3.RolesCode And T4.RolesByName='sdfsaf' Where T1.ModuleName='NMeasure'OLEDB - SetCommandText
OLEDB - ICommandPrepare
OLEDB - Prepare
OLEDB - Execute
OLEDB - GetResult
OLEDB - IColumnsInfo
OLEDB - GetColumnInfo
OLEDB - Release
OLEDB - IAccessor
OLEDB - CreateAccessor
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - GetData
OLEDB - ReleaseRows
OLEDB - GetNextRows
OLEDB - Release
OLEDB - ReleaseAccessor
*************************************************************