Tempory Recordset question

Tempory Recordset question

Postby Marc Vanzegbroeck » Sat Sep 24, 2016 9:13 am

In my program I select a list of records that a client have to order.
There he can delete the records he doesn't want to order.

In my old program, where I use DBF, I did a 'copy to for' to a temporary database of the records, and open it.
There the client can delete the records he doesn't want.

In my SQL-version, I open a recordset of the records with a SELECT FROM ... WHERE ....
Than the client get te records he can order.

The problem now is, if he delete the records, he doesn't want, the also are deleted from the table in my SQL-database :(

Is there a way that I can open it like a temporary recordset, that doesn't affect the original table?
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: Tempory Recordset question

Postby Enrico Maria Giordano » Sat Sep 24, 2016 9:32 am

Search Google for "ado disconnected recordset".

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

Re: Tempory Recordset question

Postby Marc Vanzegbroeck » Sat Sep 24, 2016 10:42 am

Hi,

I found that I have to disconnect from the database bu setting ActiveConnection to nothing.

I have tried with
Code: Select all  Expand view
oRs:ActiveConnection:hObj := nil
 
but the program keep deleting from the table :(
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: Tempory Recordset question

Postby Enrico Maria Giordano » Sat Sep 24, 2016 10:50 am

Try closing the connection too.

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

Re: Tempory Recordset question

Postby Marc Vanzegbroeck » Sat Sep 24, 2016 11:28 am

Then, I can't use the Recordset anymore. I want to use it local..0
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: Tempory Recordset question

Postby Enrico Maria Giordano » Sat Sep 24, 2016 11:30 am

It should be possible. Try changing oRs:CursorLocation.

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

Re: Tempory Recordset question

Postby Marc Vanzegbroeck » Sat Sep 24, 2016 12:39 pm

This is what I'm using, but the connection stay :(
Code: Select all  Expand view

            oRs = CREATEOBJECT( "ADODB.Recordset" )
            oRs:cursortype :=1
            oRs:cursorlocation :=3
            oRs:locktype := 3
            oRs:open('SELECT * FROM artikel',Connectionstring)
            oRs:ActiveConnection:hObj := nil
 
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: Tempory Recordset question

Postby Enrico Maria Giordano » Sat Sep 24, 2016 12:43 pm

As I already said, try to close the connection:

Code: Select all  Expand view
oRs:ActiveConnection:Close()


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

Re: Tempory Recordset question

Postby Armando » Sat Sep 24, 2016 12:51 pm

Marc:

Perhaps wit the next sample:

Code: Select all  Expand view

            oRs = CREATEOBJECT( "ADODB.Recordset" )
            oRs:cursortype :=1         // Try with number 2  adOpenDynamic
            oRs:cursorlocation :=3    // adUseClient
            oRs:locktype := 3           // adLockOptimistic
            oRs:open('SELECT * FROM artikel',Connectionstring)
        oRsWrk:Properties("Unique Table"):Value := "artikel"   // Here
            oRs:ActiveConnection:hObj := nil

 


Best regards
SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
User avatar
Armando
 
Posts: 3223
Joined: Fri Oct 07, 2005 8:20 pm
Location: Toluca, México

Re: Tempory Recordset question

Postby Marc Vanzegbroeck » Sat Sep 24, 2016 12:55 pm

Enrico Maria Giordano wrote:As I already said, try to close the connection:

Code: Select all  Expand view
oRs:ActiveConnection:Close()


EMG


Enrico, as i said, than I can't browse the recordset anymore.
Code: Select all  Expand view
oRs = CREATEOBJECT( "ADODB.Recordset" )
oRs:cursortype :=1
oRs:cursorlocation :=3
oRs:locktype := 3 //alleen lees
oRs:open('SELECT * FROM artikel',Connectionstring)
?oRs:recordcount() -----> Give number of records  
oRs:ActiveConnection:close()
?oRs:recordcount() ------> Give error
 
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: Tempory Recordset question

Postby nageswaragunupudi » Sat Sep 24, 2016 1:55 pm

Detatched RecordSets:

Setting oRs.ActiveConnection = Nothing works well with VB.
But I never succeeded in doing it with (x)Harbour so far.
I am eager to learn if a working sample is posted to do this.

To achieve the same objective I adopt 2 alternatives:

1) Open with locktype adLockBatchOptimistic and never use oRs:UpdateBatch
Code: Select all  Expand view

function Test()

   local oCn, oRs

   oCn   := FW_OpenAdoConnection( "testins.mdb" )
   oRs   := FW_OpenRecordSet( oCn, "testtable", adLockBatchOptimistic )

   xbrowser oRs fastedit
   // Edit, delete, addnew as you like
   // but do not use oRs:UpdateBatch()

   oRs:Close()
   oCn:Close()

return nil
 


My preferred and safest way is to save a local copy of the recordset and use it
Example:
Code: Select all  Expand view

function TestDiscon()

   local oCn, oRs
   local cDat := "mycopy.dat"

   oCn   := FW_OpenAdoConnection( "testins.mdb" )
   oRs   := FW_OpenRecordSet( oCn, "testtable", adLockBatchOptimistic )

   if File( cDat )
      FErase( cDat )
   endif
   oRs:Save( cDat )
   oRs:Close()
   oCn:Close()

   oRs   := FW_OpenRecordSet( nil, cDat )
   // oRs:ActiveConnection is NIL
   xbrowser oRs fastedit

   // Edit, delete, addnew as you like

   // In case you still like to save changes
   // Assign oRs:ActiveConnection := oCn
   // and then oRs:UpdateBatch

   oRs:Close()

return nil
 


For more details about the usage
viewtopic.php?f=3&t=26907&p=149354&hilit=recordset+locally#p149354
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10632
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Tempory Recordset question

Postby Rick Lipkin » Sat Sep 24, 2016 2:44 pm

Marc

As Rao suggests .. You could use\create a temp Access table .mdb OR good old dbf\cdx .. When I write reports, I always create temp .dbf\cdx and write my oRs results to the temp database somewhere on the client machine. When the report is done, Close Databases, and ferase() works just fine for me.

Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Tempory Recordset question

Postby Marc Vanzegbroeck » Sat Sep 24, 2016 3:04 pm

Roa, Rick,

Thank you for the information.
Save it local will be the best option.
I even can do it like I did before, in a DBF-file :D
Then I did a 'copy to ... for' to a temporay DBF, and open that DBF
Now I can save the recordset to a DBF, and open it :D
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: Tempory Recordset question

Postby nageswaragunupudi » Sat Sep 24, 2016 3:42 pm

Code: Select all  Expand view
function FW_AdoExportToDBF( oRs, cDbf, lEditStruct )


FWH has answers to many issues.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10632
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Tempory Recordset question

Postby nageswaragunupudi » Sat Sep 24, 2016 3:43 pm

Still by experience, let me advise my second option to save the recordset and open independently is the best option.
Please do not consider other alternatives.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10632
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Natter and 51 guests