How to copy a row of a rowset
How to copy a row of a rowset
Hi Guys,
I have a rowset oRs that have a lot of rows.
I wanted to copy only one row/record of oRs to a new rowset(oRL). Is It possible ?
I have a rowset oRs that have a lot of rows.
I wanted to copy only one row/record of oRs to a new rowset(oRL). Is It possible ?
Re: How to copy a row of a rowset
Simple, use MYSQL
INSERT INTO clientes SELECT * FROM personas WHERE id='42431-01'
Hope it helps
From Chile
Adolfo
INSERT INTO clientes SELECT * FROM personas WHERE id='42431-01'
Hope it helps
From Chile
Adolfo
Ji,ji,ji... buena la cosa... "all you need is code"
http://www.xdata.cl - Desarrollo Inteligente
----------
Lenovo Legion Y520, 16GB Ram, 1 TB NVME M.2, 1 TB SSD, GTX 1050
http://www.xdata.cl - Desarrollo Inteligente
----------
Lenovo Legion Y520, 16GB Ram, 1 TB NVME M.2, 1 TB SSD, GTX 1050
Re: How to copy a row of a rowset
Thank you,
But I don't want insert a new record. I want create a new rowset from a line of previous rowset.
But I don't want insert a new record. I want create a new rowset from a line of previous rowset.
Re: How to copy a row of a rowset
Una idea
Code: Select all
//RsToHash( oRs, [nRows], [nStart], [aFields] )
hPrueba := RsToHash( oRsFtr, 1, 1 )
xbrowse( hPrueba )
Saludos
LEANDRO ALFONSO
SISTEMAS LYMA - BASE
Bogotá (Colombia)
[ FWH 19.09 ] [ xHarbour 1.2.3 Intl. (SimpLex) (Build 20190613) ] [ Embarcadero C++ 7.30 for Win32 ]
LEANDRO ALFONSO
SISTEMAS LYMA - BASE
Bogotá (Colombia)
[ FWH 19.09 ] [ xHarbour 1.2.3 Intl. (SimpLex) (Build 20190613) ] [ Embarcadero C++ 7.30 for Win32 ]
Re: How to copy a row of a rowset
Thanks Leandro,
It's almost what I wanted. But in your code you are creating a hash and I wanted created a new rowset.
It's almost what I wanted. But in your code you are creating a hash and I wanted created a new rowset.
Re: How to copy a row of a rowset
Otra idea
Code: Select all
RsGetRows( oRs, [nRows], [nStart], [aFields] )
Saludos
LEANDRO ALFONSO
SISTEMAS LYMA - BASE
Bogotá (Colombia)
[ FWH 19.09 ] [ xHarbour 1.2.3 Intl. (SimpLex) (Build 20190613) ] [ Embarcadero C++ 7.30 for Win32 ]
LEANDRO ALFONSO
SISTEMAS LYMA - BASE
Bogotá (Colombia)
[ FWH 19.09 ] [ xHarbour 1.2.3 Intl. (SimpLex) (Build 20190613) ] [ Embarcadero C++ 7.30 for Win32 ]
Re: How to copy a row of a rowset
It's also returning an array and I wanted a object
- Marc Venken
- Posts: 727
- Joined: Tue Jun 14, 2016 7:51 am
Re: How to copy a row of a rowset
nTotal := oCn:QueryResult( "SELECT SUM(SALARY) FROM CUSTOMER" )
Read field values of a row into an array
CODE: SELECT ALL EXPAND VIEW
cList := "ID,FIRST,LAST,CITY,SALARY"
aRow := oCn:QueryResult( "SELECT " + cList + " FROM CUSTOMER WHERE ID = 100" )
Copy the same values to another row at ID = 150:
CODE: SELECT ALL EXPAND VIEW
// modify/edit any values of the aRow
aRow[ 1 ] := 150 // do not change for saving to same row
oCn:Insert( "customer", cList, aRow, .t. ) // .T. indicates update if primary key exists
Copy present values of a row and append as new record
CODE: SELECT ALL EXPAND VIEW
aRow := oCn:QueryResult( "SELECT * FROM CUSTOMER WHERE ID = 100" )
aRow[ 1 ] := 0
oCn:Insert( "customer", nil, aRow ) // fwh 16.11. aFields can be nil
Maybe this can help : Examples from this link :
http://forums.fivetechsupport.com/viewt ... =3&t=32737
Read field values of a row into an array
CODE: SELECT ALL EXPAND VIEW
cList := "ID,FIRST,LAST,CITY,SALARY"
aRow := oCn:QueryResult( "SELECT " + cList + " FROM CUSTOMER WHERE ID = 100" )
Copy the same values to another row at ID = 150:
CODE: SELECT ALL EXPAND VIEW
// modify/edit any values of the aRow
aRow[ 1 ] := 150 // do not change for saving to same row
oCn:Insert( "customer", cList, aRow, .t. ) // .T. indicates update if primary key exists
Copy present values of a row and append as new record
CODE: SELECT ALL EXPAND VIEW
aRow := oCn:QueryResult( "SELECT * FROM CUSTOMER WHERE ID = 100" )
aRow[ 1 ] := 0
oCn:Insert( "customer", nil, aRow ) // fwh 16.11. aFields can be nil
Maybe this can help : Examples from this link :
http://forums.fivetechsupport.com/viewt ... =3&t=32737
Marc Venken
Using: FWH 20.08 with Harbour
Using: FWH 20.08 with Harbour
Re: How to copy a row of a rowset
Thanks,
I already read this topic and did not find what i need.
I already read this topic and did not find what i need.
Re: How to copy a row of a rowset
En ese orden de ideas, ya tienes el objeto, lo único que hay que hacer es ubicarse sobre el registro a leer y llamar la linea completa, así:
Code: Select all
oRow := oRs:Fields
Saludos
LEANDRO ALFONSO
SISTEMAS LYMA - BASE
Bogotá (Colombia)
[ FWH 19.09 ] [ xHarbour 1.2.3 Intl. (SimpLex) (Build 20190613) ] [ Embarcadero C++ 7.30 for Win32 ]
LEANDRO ALFONSO
SISTEMAS LYMA - BASE
Bogotá (Colombia)
[ FWH 19.09 ] [ xHarbour 1.2.3 Intl. (SimpLex) (Build 20190613) ] [ Embarcadero C++ 7.30 for Win32 ]
Re: How to copy a row of a rowset
oCurrentRs := oCn:Query( "SELECT * FROM CUSTOMER" )
oNewRow := oCn:Query( "SELECT * FROM CUSTOMER WHERE ID < 0" ) //Get an empty row (There is no customer has a negative id)
FOR nI=1 TO oCurrentRs:FCount()
oNewRow:FieldPut(nI, oCurrentRs:FieldGet(nI))
NEXT
oNewRow := oCn:Query( "SELECT * FROM CUSTOMER WHERE ID < 0" ) //Get an empty row (There is no customer has a negative id)
FOR nI=1 TO oCurrentRs:FCount()
oNewRow:FieldPut(nI, oCurrentRs:FieldGet(nI))
NEXT
- nageswaragunupudi
- Posts: 8017
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
Re: How to copy a row of a rowset
Code: Select all
aRows := oRs:GetRows( 1, oRs:KeyNo )
Code: Select all
{ { col1value, col2value, ... colNvalue } }
But you can not create a new rowset in memory with this data.
A RowSet can be created ONLY by reading data from the MySql database via an sql query.
If you want to create an object, which works similary, holding this data, you can create TArrayData object
Code: Select all
oData := TArrayData():New( aRows, oRs:aStructure )
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
Re: How to copy a row of a rowset(solved)
Thank you !
Re: How to copy a row of a rowset
Good morning,nageswaragunupudi wrote:This gives a two-dimensional array with a single rowCode: Select all
aRows := oRs:GetRows( 1, oRs:KeyNo )
If you want to insert the data into another existing RowSet with identical structure, you can do it using oRs2:AddNew( aFields, aRows[ 1 ] ) }Code: Select all
{ { col1value, col2value, ... colNvalue } }
But you can not create a new rowset in memory with this data.
A RowSet can be created ONLY by reading data from the MySql database via an sql query.
If you want to create an object, which works similary, holding this data, you can create TArrayData objectCode: Select all
oData := TArrayData():New( aRows, oRs:aStructure )
In oRs:aStructure the field type for the “primary key” is “+” instead of “N”, so the “primary key” value is not copied properly in TdataArray
The solution is either modify TdataArray and add ‘+” as a field type, like “N”, “D”, “C”, etc. or put this in your code.
Code: Select all
aRows := oRs:GetRows( )
aStru := aclone( oRs:aStructure )
aeval( aStru, { | aAr , n | iif( aAr[2]=='+' , aAr[2]:='N',nil) } )
oData := TArrayData():New( aRows, aStru )
- nageswaragunupudi
- Posts: 8017
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact: