Pasar query a un arreglo

User avatar
Compuin
Posts: 1250
Joined: Tue Dec 28, 2010 1:29 pm
Location: Quebec, Canada
Has thanked: 7 times
Been thanked: 3 times

Pasar query a un arreglo

Post by Compuin »

Hola foro,

Como puedo leer una tabla mysql y pasar su contenido a un arreglo?

Hay algun ejemplo en Fivewin?

Gracias
FWH 20.12
Hbmk2 32/64 Bits (Build 19.29.30133)
Microsoft Visual C 32 Bits
MySql 8.0.24 32/64 Bits
VS Code
User avatar
joseluisysturiz
Posts: 2064
Joined: Fri Jan 06, 2006 9:28 pm
Location: Guatire - Caracas - Venezuela
Contact:

Re: Pasar query a un arreglo

Post by joseluisysturiz »

Usa oQry:fillarray...es lo mejor y mas rapido, saludos... :shock:

Code: Select all | Expand


// FILLARRAY
oQry:FillArray( {| aRow | AAdd( oBrw:aArrayData, { aRow[2], aRow[4] } ) } ) // CON POSICION CAMPO

oBrw:aArrayData := oQry:FillArray( , { "vende_cedula", "vende_apellidos" } ) // CON CAMPOS. PARA LOS xBRW O UN ARRAY

oQry:FillArray( {| aRow | ( AAdd( Array1, cValToChar( aRow[1] ) ) ,; // PARA LOS COMBOBOX CON QRY
                             AAdd( Array2, aRow[2]) ) }, )
 
Dios no está muerto...

Gracias a mi Dios ante todo!
User avatar
Compuin
Posts: 1250
Joined: Tue Dec 28, 2010 1:29 pm
Location: Quebec, Canada
Has thanked: 7 times
Been thanked: 3 times

Re: Pasar query a un arreglo

Post by Compuin »

joseluisysturiz wrote:Usa oQry:fillarray...es lo mejor y mas rapido, saludos... :shock:

Code: Select all | Expand


// FILLARRAY
oQry:FillArray( {| aRow | AAdd( oBrw:aArrayData, { aRow[2], aRow[4] } ) } ) // CON POSICION CAMPO

oBrw:aArrayData := oQry:FillArray( , { "vende_cedula", "vende_apellidos" } ) // CON CAMPOS. PARA LOS xBRW O UN ARRAY

oQry:FillArray( {| aRow | ( AAdd( Array1, cValToChar( aRow[1] ) ) ,; // PARA LOS COMBOBOX CON QRY
                             AAdd( Array2, aRow[2]) ) }, )
 


Muchas gracias paisano
FWH 20.12
Hbmk2 32/64 Bits (Build 19.29.30133)
Microsoft Visual C 32 Bits
MySql 8.0.24 32/64 Bits
VS Code
User avatar
joseluisysturiz
Posts: 2064
Joined: Fri Jan 06, 2006 9:28 pm
Location: Guatire - Caracas - Venezuela
Contact:

Re: Pasar query a un arreglo

Post by joseluisysturiz »

Olvide comentarte que esto es usando TDolphin, saludos... :shock:
Dios no está muerto...

Gracias a mi Dios ante todo!
User avatar
Compuin
Posts: 1250
Joined: Tue Dec 28, 2010 1:29 pm
Location: Quebec, Canada
Has thanked: 7 times
Been thanked: 3 times

Re: Pasar query a un arreglo

Post by Compuin »

joseluisysturiz wrote:Olvide comentarte que esto es usando TDolphin, saludos... :shock:


Si, imagino que es TDolphin

Yo uso Eagle1, deberia funcionar ya que solo es el resultado del query
FWH 20.12
Hbmk2 32/64 Bits (Build 19.29.30133)
Microsoft Visual C 32 Bits
MySql 8.0.24 32/64 Bits
VS Code
User avatar
joseluisysturiz
Posts: 2064
Joined: Fri Jan 06, 2006 9:28 pm
Location: Guatire - Caracas - Venezuela
Contact:

Re: Pasar query a un arreglo

Post by joseluisysturiz »

fillarray si no me equivoco, es un methodo de TDolphin, en FWMaria o algo asi nativo de FW se usa algo diferente, aun no he migrado a el nativo de FW, pero para alla voy Dios mediante, tambien puedes hacer un recorrido del qry y usar aadd(array, valores/{valores}), es lo mas clasico, saludos... :shock:
Dios no está muerto...

Gracias a mi Dios ante todo!
User avatar
nageswaragunupudi
Posts: 10721
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 8 times
Contact:

Re: Pasar query a un arreglo

Post by nageswaragunupudi »

Native FWH:
Simple and the fastest:

aData := oCn:Execute( cQry )

Example:

Code: Select all | Expand


aStates := oCn:Execute( "select code,name from states" )
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
Compuin
Posts: 1250
Joined: Tue Dec 28, 2010 1:29 pm
Location: Quebec, Canada
Has thanked: 7 times
Been thanked: 3 times

Re: Pasar query a un arreglo

Post by Compuin »

nageswaragunupudi wrote:Native FWH:
Simple and the fastest:

aData := oCn:Execute( cQry )

Example:

Code: Select all | Expand


aStates := oCn:Execute( "select code,name from states" )
 


Thanks Mr Rao
FWH 20.12
Hbmk2 32/64 Bits (Build 19.29.30133)
Microsoft Visual C 32 Bits
MySql 8.0.24 32/64 Bits
VS Code
User avatar
Compuin
Posts: 1250
Joined: Tue Dec 28, 2010 1:29 pm
Location: Quebec, Canada
Has thanked: 7 times
Been thanked: 3 times

Re: Pasar query a un arreglo

Post by Compuin »

joseluisysturiz wrote:fillarray si no me equivoco, es un methodo de TDolphin, en FWMaria o algo asi nativo de FW se usa algo diferente, aun no he migrado a el nativo de FW, pero para alla voy Dios mediante, tambien puedes hacer un recorrido del qry y usar aadd(array, valores/{valores}), es lo mas clasico, saludos... :shock:


Gracias Jose Luis por la aclaratoria
FWH 20.12
Hbmk2 32/64 Bits (Build 19.29.30133)
Microsoft Visual C 32 Bits
MySql 8.0.24 32/64 Bits
VS Code
User avatar
joseluisysturiz
Posts: 2064
Joined: Fri Jan 06, 2006 9:28 pm
Location: Guatire - Caracas - Venezuela
Contact:

Re: Pasar query a un arreglo

Post by joseluisysturiz »

nageswaragunupudi wrote:Native FWH:
Simple and the fastest:

aData := oCn:Execute( cQry )

Example:

Code: Select all | Expand


aStates := oCn:Execute( "select code,name from states" )
 


Buen dia Mr. NAO, si ya tengo un queri hecho con fillarray selecciono solo los campos que deseo pasar al array sin necesidad de hacer la consulta al momento, como lo haria con la nativa de FW.? gracias... :shock:
Dios no está muerto...

Gracias a mi Dios ante todo!
User avatar
nageswaragunupudi
Posts: 10721
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 8 times
Contact:

Re: Pasar query a un arreglo

Post by nageswaragunupudi »

If you already made a query (we call it RowSet), then you can use method GetRows(), which is similar to FillArray() of Dolphin.

aData := oRs:GetRows( [nRows], [nFromRow], [aFieldNames] )

Example:

Code: Select all | Expand


oRs := oCn:RowSet( "customer" )
aDataFull := oRs:GetRows()
aDataPart := oRs:GetRows( 20, 101, { "first", "city", "salary" } )
 


But, if you did not read query (rowset) already, we can save lot of time by directly reading the data into an array, instead of first reading into a query and then copying data from query into an array.
This is simple and fast

Code: Select all | Expand


aData := oCn:Execute( "select first, city, salary from customer where id between 101 and 120" )
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
joseluisysturiz
Posts: 2064
Joined: Fri Jan 06, 2006 9:28 pm
Location: Guatire - Caracas - Venezuela
Contact:

Re: Pasar query a un arreglo

Post by joseluisysturiz »

nageswaragunupudi wrote:If you already made a query (we call it RowSet), then you can use method GetRows(), which is similar to FillArray() of Dolphin.

aData := oRs:GetRows( [nRows], [nFromRow], [aFieldNames] )

Example:

Code: Select all | Expand


oRs := oCn:RowSet( "customer" )
aDataFull := oRs:GetRows()
aDataPart := oRs:GetRows( 20, 101, { "first", "city", "salary" } )
 


But, if you did not read query (rowset) already, we can save lot of time by directly reading the data into an array, instead of first reading into a query and then copying data from query into an array.
This is simple and fast

Code: Select all | Expand


aData := oCn:Execute( "select first, city, salary from customer where id between 101 and 120" )
 



Excelente, veo que se porta igual que fillarray, ahora otra duda...se puede agrgar un valor que no sea de la consulta, como por ejemplo un valor booleano o el valor de una variable.?

ejemplo:

Code: Select all | Expand


aDataPart := oRs:GetRows( 20, 101, { "first", "city", "salary", .f. } )
// Esto seriviria para usar un xbrowse y usar setcheck()

aDataPart := oRs:GetRows( 20, 101, { "first", "city", "salary", nom_var } )

// nom_var seria una VAR externa al query, con fillarray no se como hacerlo, gracias... :shock:
 
Dios no está muerto...

Gracias a mi Dios ante todo!
User avatar
joseluisysturiz
Posts: 2064
Joined: Fri Jan 06, 2006 9:28 pm
Location: Guatire - Caracas - Venezuela
Contact:

Re: Pasar query a un arreglo

Post by joseluisysturiz »

Quiero empezar a migrar de TDolphin a FWMaria la nativa de FW, por donde inicio.? gracias... :shock:
Dios no está muerto...

Gracias a mi Dios ante todo!
User avatar
nageswaragunupudi
Posts: 10721
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 8 times
Contact:

Re: Pasar query a un arreglo

Post by nageswaragunupudi »

Excelente, veo que se porta igual que fillarray, ahora otra duda...se puede agrgar un valor que no sea de la consulta, como por ejemplo un valor booleano o el valor de una variable.?


Every element of the array should be a field name or field number or a character expression using or not using field names.

Example:

Code: Select all | Expand


   PRIVATE n

   oRs   := oCn:customer   // where customer is the table name
   n     := 100
   aData := oRs:GetRows( 5, 11, ;
      { "first-', '+last", "salary/100", "FW_MTHSLAPSED(HireDate,Date())", "n := n + 1" } )
 


Image
Regards

G. N. Rao.
Hyderabad, India
User avatar
joseluisysturiz
Posts: 2064
Joined: Fri Jan 06, 2006 9:28 pm
Location: Guatire - Caracas - Venezuela
Contact:

Re: Pasar query a un arreglo

Post by joseluisysturiz »

Super excelente Mr NAO...Quiero empezar a migrar de TDolphin a FWMaria la nativa de FW, por donde inicio.? gracias... :shock:
Dios no está muerto...

Gracias a mi Dios ante todo!
Post Reply