ADO RDD xHarbour

Re: ADO RDD xHarbour

Postby Antonio Linares » Wed Mar 25, 2015 4:23 pm

Antonio,

I am checking the properties and methods of the ADO Connection object:

https://msdn.microsoft.com/en-us/library/windows/desktop/ms681546(v=vs.85).aspx

Please do a MsgInfo( oADODB:State ) before opening the recordset
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: ADO RDD xHarbour

Postby AHF » Wed Mar 25, 2015 6:15 pm

Antonio,

We just found out that :
RecordCount isnt always accurate:

with adUseServer (cursor supported by the provider) always return the total nr of records in table even if there is a where clause in the select like Reccount()

with adUseClient (MS ccursor ) always return the true nr of rows in the recordset

Thus the OrdKeyCount mainly needed for scrollbars will not function properly with adUseServer cursor!
Regards
Antonio H Ferreira
AHF
 
Posts: 838
Joined: Fri Feb 10, 2006 12:14 pm

Re: ADO RDD xHarbour

Postby Antonio Linares » Wed Mar 25, 2015 6:25 pm

Antonio,

Many thanks for your great feedback :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: ADO RDD xHarbour

Postby AHF » Thu Mar 26, 2015 11:32 am

Antonio,

OrdKeyCount and RECORDCOUNT might be a problem!

The only way to solve this is to:

If we use always adUseClient because ADO knows all rows and there ist any problem but performance decreases a lot. Not advisable!
IF we use adUseServer then with a WHERE clause ADO returns wrong RECORDCOUNT and OrdKeyCount!

The only solution we for this is :

If there is a WHERE clause we have to query the table with SELECT COUNT(*) FROM ctable WHERE ....
Thus in each RECORDCOUNT and OrdKeyCount values are correct.
We replace RECORDCOUNT by the following code:

Code: Select all  Expand view


STATIC FUNCTION ADORECCOUNT(nWA,oRecordSet) //AHF
   LOCAL aAWData := USRRDD_AREADATA( nWA )
   LOCAL oCon := aAWData[WA_CONNECTION]
   LOCAL nCount := 0, cSql:=""

   IF oRecordSet:CursorLocation == adUseClient
      nCount :=  oRecordSet:RecordCount
   ELSE
      IF LEN(aAWData[WA_INDEXES]) > 0 .AND. aAWData[WA_INDEXACTIVE] > 0
         oRecordSet:close()
         //Making it lightning faster
         oRecordSet:CursorLocation := adUseServer
         oRecordSet:CursorType := adOpenForwardOnly
         oRsecordSetLockType := adLockReadOnly
         //LAST PARAMTER INSERTS cSql COUNT(*) MUST BE ALL FIELDS BECAUSE IF THERE IS A NULL        
                 //FIELD COUNTS RETURNS WRONG
         cSql := IndexBuildExp(aAWData[WA_INDEXACTIVE],aAWData,.T.) //INCLUDE COUNT
         msginfo("adoreccount 2 "+CSQL)
         //LETS COUNT IT
         oRecordSet:open(cSql,oCon)
         nCount := oRecordSet:Fields( 0 ):Value
         msginfo("adoreccount 3 NRREC "+CVALTOCHAR(NCOUNT))
         oRecordSet:close()
         //RETURNING TO DEFAULT DATA
         oRecordSet:CursorType := adOpenDynamic
         oRecordSet:CursorLocation := adUseServer //adUseClient never use ths very slow!
         oRecordSet:LockType := adLockPessimistic
         cSql := IndexBuildExp(aAWData[WA_INDEXACTIVE],aAWData,.F.)  //.F. DONT INCLUDE COUNT
          msginfo("adoreccount 4 "+CSQL)
         oRecordSet:open(cSql,oCon)
      ELSE
         nCount :=  oRecordSet:RecordCount
      ENDIF
   ENDIF  
   
   RETURN nCount  

 


Do you have any other alternative? This function its called a lot and I dont know what will be effect in the overall performance. In our small trials it seems ok but .....

I miss good old DBF or ADS:(
Regards
Antonio H Ferreira
AHF
 
Posts: 838
Joined: Fri Feb 10, 2006 12:14 pm

Re: ADO RDD xHarbour

Postby Antonio Linares » Thu Mar 26, 2015 3:57 pm

Antonio,

As far as I know oRs:RecordCount() returns the number of records of the recordset
so if you use a WHERE clause then you get less records.

Lets ask Mr. Rao
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: ADO RDD xHarbour

Postby Enrico Maria Giordano » Thu Mar 26, 2015 4:02 pm

Antonio,

AHF wrote:If we use always adUseClient because ADO knows all rows and there ist any problem but performance decreases a lot.


Using adUseClient the performance is better than adUseServer!

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8715
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: ADO RDD xHarbour

Postby AHF » Thu Mar 26, 2015 4:39 pm

Enrico,

Enrico Maria Giordano wrote:Antonio,

AHF wrote:If we use always adUseClient because ADO knows all rows and there ist any problem but performance decreases a lot.


Using adUseClient the performance is better than adUseServer!

EMG


What DB you use?

adUseClient would be much easier for adordd (bookmarks etc) but everything I read covering this indicates that adUseClient its much slower and should be avoid.

Please note that the I'm using SELECT * FROM ... in adordd thats its really not good SQL practice but compatibility much be achieved.
Regards
Antonio H Ferreira
AHF
 
Posts: 838
Joined: Fri Feb 10, 2006 12:14 pm

Re: ADO RDD xHarbour

Postby AHF » Thu Mar 26, 2015 4:49 pm

Antonio,

Antonio Linares wrote:Antonio,

As far as I know oRs:RecordCount() returns the number of records of the recordset
so if you use a WHERE clause then you get less records.

Lets ask Mr. Rao


Opening same dbf in 2 dif areas

One with normal index the RECORDCOUNT = nr of records dbf = ORDKEYCOUNT
Second with conditional index SELECT WHERE ... the RECORDCOUNT = nr of records dbf <> ORDKEYCOUNT that is = nr of records within the WHERE clause.
Moving through the recordset will soon or later get an error.
Please note that the recordset has in fact only the records within the condition although RECORDCOUNT reports all records.

This is using serverside cursor.
Regards
Antonio H Ferreira
AHF
 
Posts: 838
Joined: Fri Feb 10, 2006 12:14 pm

Re: ADO RDD xHarbour

Postby Enrico Maria Giordano » Thu Mar 26, 2015 5:29 pm

Antonio,

AHF wrote:What DB you use?


MDB, MSSQL and MySQL.

AHF wrote:adUseClient would be much easier for adordd (bookmarks etc) but everything I read covering this indicates that adUseClient its much slower and should be avoid.


adUseClient is faster in my experience.

AHF wrote:Please note that the I'm using SELECT * FROM ... in adordd thats its really not good SQL practice but compatibility much be achieved.


???

SELECT * FROM is the base of all SQL queries. What else would you want to use?

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8715
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: ADO RDD xHarbour

Postby AHF » Thu Mar 26, 2015 5:57 pm

Enrico Maria Giordano wrote:
AHF wrote:Please note that the I'm using SELECT * FROM ... in adordd thats its really not good SQL practice but compatibility much be achieved.


???

SELECT * FROM is the base of all SQL queries. What else would you want to use?

EMG


I mean avoid loading all the fields instead of just the ones we need for the task.
Regards
Antonio H Ferreira
AHF
 
Posts: 838
Joined: Fri Feb 10, 2006 12:14 pm

Re: ADO RDD xHarbour

Postby Enrico Maria Giordano » Thu Mar 26, 2015 6:02 pm

Antonio

AHF wrote:I mean avoid loading all the fields instead of just the ones we need for the task.


Ok, but what if I need all the fields? :-)

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8715
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: ADO RDD xHarbour

Postby AHF » Thu Mar 26, 2015 6:10 pm

Enrico Maria Giordano wrote:Antonio

AHF wrote:I mean avoid loading all the fields instead of just the ones we need for the task.


Ok, but what if I need all the fields? :-)

EMG


Then SELECT colname FROM table unfortunatly in adordd its always all the fields! Its the price for no code change.
Regards
Antonio H Ferreira
AHF
 
Posts: 838
Joined: Fri Feb 10, 2006 12:14 pm

Re: ADO RDD xHarbour

Postby Enrico Maria Giordano » Thu Mar 26, 2015 6:28 pm

Antonio,

AHF wrote:Then SELECT colname FROM table unfortunatly in adordd its always all the fields! Its the price for no code change.


Ok, I see, you're right.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8715
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: ADO RDD xHarbour

Postby AHF » Thu Mar 26, 2015 6:58 pm

Antonio,

Can you find rdd function for close all ?
Regards
Antonio H Ferreira
AHF
 
Posts: 838
Joined: Fri Feb 10, 2006 12:14 pm

Re: ADO RDD xHarbour

Postby Antonio Linares » Fri Mar 27, 2015 5:41 am

Do you mean DbCloseAll() ?

I think you have to implement UR_CLOSE
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

PreviousNext

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 83 guests