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 ?
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 ?
Simple, use MYSQL
INSERT INTO clientes SELECT * FROM personas WHERE id='42431-01'
Hope it helps
From Chile
Adolfo
Thank you,
But I don't want insert a new record. I want create a new rowset from a line of previous rowset.
//RsToHash( oRs, [nRows], [nStart], [aFields] )
hPrueba := RsToHash( oRsFtr, 1, 1 )
xbrowse( hPrueba )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 also returning an array and I wanted a object
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 :
&
Thanks,
I already read this topic and did not find what i need.
oRow := oRs:FieldsoCurrentRs := 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
aRows := oRs:GetRows( 1, oRs:KeyNo ){ { col1value, col2value, ... colNvalue } }oData := TArrayData():New( aRows, oRs:aStructure )Thank you !
nageswaragunupudi wrote:aRows := oRs:GetRows( 1, oRs:KeyNo )
This gives a two-dimensional array with a single row
{ { col1value, col2value, ... colNvalue } }
If you want to insert the data into another existing RowSet with identical structure, you can do it using oRs2:AddNew( aFields, aRows[ 1 ] ) }
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
oData := TArrayData():New( aRows, oRs:aStructure )
aRows := oRs:GetRows( )
aStru := aclone( oRs:aStructure )
aeval( aStru, { | aAr , n | iif( aAr[2]=='+' , aAr[2]:='N',nil) } )
oData := TArrayData():New( aRows, aStru )ok thanks