Retrieving entire columns from a resultset

Retrieving entire columns from a resultset

am 28.06.2005 20:18:43 von Mithila Patwardhan

------_=_NextPart_001_01C57C0D.D151E366
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

Hi,=20

I would like to know if there is anyway of retreiving an entire column
of data from a resultset into say an array or a vector.=20

e.g. If the resultset contains columns ID (int), Name(varchar), age(int)
then I'd like retrieve the ID values from each tuple in one go into say
an int array or a vector.=20

I am using a mysql 4.0.12 database and a mysql ODBC 3.51 driver to
connect to it. Language - C++ compatible with visual studio 6.

Thanks,

Mithila


------_=_NextPart_001_01C57C0D.D151E366--

RE: Retrieving entire columns from a resultset

am 29.06.2005 01:20:41 von jbonnett

Yes, you write a loop that retrieves each row from the result set and
loads the columns into an array row by row. If you want to do it in one
go, write yourself a sub-routine.

I have lots of little routines that populate grids and list/combo boxes
like this, but there are not any pre-existing routines like this, as far
as I know.

By the way, loading whole columns into an array sounds to me like the
wrong way to use a database. What are you going to do with the data once
it is in the array? It may be that you can just formulate different
query(s) and get the results you want without using an array. Without
knowing what you are doing I don't know if this is possible in your case
but I do come across people not using databases properly. They don't
know SQL very well so they suck large chunks of data into arrays and
process it all in memory. C/C++ programmers seem to be more prone to
this in my experience as they are used to working with complex in memory
structures. The database engine does this sort of thing itself but is
generally highly optimised and will mostly do it better that you can.
You just need to ask the right question, i.e. write the right query.
These comments may not apply to you, but just in case.

John Bonnett

-----Original Message-----
From: Mithila Patwardhan [mailto:mpatwardhan@vitalimages.com]=20
Sent: Wednesday, 29 June 2005 3:49 AM
To: myodbc@lists.mysql.com
Subject: Retrieving entire columns from a resultset

Hi,=20

I would like to know if there is anyway of retreiving an entire column
of data from a resultset into say an array or a vector.=20

e.g. If the resultset contains columns ID (int), Name(varchar), age(int)
then I'd like retrieve the ID values from each tuple in one go into say
an int array or a vector.=20

I am using a mysql 4.0.12 database and a mysql ODBC 3.51 driver to
connect to it. Language - C++ compatible with visual studio 6.

Thanks,

Mithila


--
MySQL ODBC Mailing List
For list archives: http://lists.mysql.com/myodbc
To unsubscribe: http://lists.mysql.com/myodbc?unsub=3Dgcdmo-myodbc@m.gmane.o rg

RE: Retrieving entire columns from a resultset

am 29.06.2005 18:38:59 von Mithila Patwardhan

Hi John,

Thanks a lot for that detailed reply!

I am not going planning to do any kind of sorting / searching activities
on the data retrieved columnwise.

To give you an idea of what I wish to do - I have a few tables in the
database. I have one class that reflects one specific table from the
database. So, if I have a studentinfo table in the database then I have
a StudentInfo class. Objects of that class would represent tuples from
the studentinfo table.

I have a situation where I retrieve many tuples from the database at
once and want to load the tuples into objects of say, the StudentInfo
class. I have a vector of objects of that class. Now, the datatypes of
say name, age and GPA would be different. Therefore, a mechanism where
retrieve all the tuples by binding columns and then sqlfetching data
works out to be a bit painful - every datatype has to be handled in its
own way.=20

So, I thought if there is a way of getting an entire column of the
resulset at once then I could instantiate that particular data member of
every object in my vector.

My goal here is to enhance data retrieval speeds.

Does this make my problem any clearer?

Regards,
Mithila

-----Original Message-----
From: jbonnett@sola.com.au [mailto:jbonnett@sola.com.au]=20
Sent: Tuesday, June 28, 2005 6:21 PM
To: Mithila Patwardhan; myodbc@lists.mysql.com
Subject: RE: Retrieving entire columns from a resultset

Yes, you write a loop that retrieves each row from the result set and
loads the columns into an array row by row. If you want to do it in one
go, write yourself a sub-routine.

I have lots of little routines that populate grids and list/combo boxes
like this, but there are not any pre-existing routines like this, as far
as I know.

By the way, loading whole columns into an array sounds to me like the
wrong way to use a database. What are you going to do with the data once
it is in the array? It may be that you can just formulate different
query(s) and get the results you want without using an array. Without
knowing what you are doing I don't know if this is possible in your case
but I do come across people not using databases properly. They don't
know SQL very well so they suck large chunks of data into arrays and
process it all in memory. C/C++ programmers seem to be more prone to
this in my experience as they are used to working with complex in memory
structures. The database engine does this sort of thing itself but is
generally highly optimised and will mostly do it better that you can.
You just need to ask the right question, i.e. write the right query.
These comments may not apply to you, but just in case.

John Bonnett

-----Original Message-----
From: Mithila Patwardhan [mailto:mpatwardhan@vitalimages.com]=20
Sent: Wednesday, 29 June 2005 3:49 AM
To: myodbc@lists.mysql.com
Subject: Retrieving entire columns from a resultset

Hi,=20

I would like to know if there is anyway of retreiving an entire column
of data from a resultset into say an array or a vector.=20

e.g. If the resultset contains columns ID (int), Name(varchar), age(int)
then I'd like retrieve the ID values from each tuple in one go into say
an int array or a vector.=20

I am using a mysql 4.0.12 database and a mysql ODBC 3.51 driver to
connect to it. Language - C++ compatible with visual studio 6.

Thanks,

Mithila


--=20
MySQL ODBC Mailing List
For list archives: http://lists.mysql.com/myodbc
To unsubscribe:
http://lists.mysql.com/myodbc?unsub=3Dmpatwardhan@vitalimage s.com


____________________________________________________________ ____________
This email has been scanned for all viruses and found to be virus free.
If you have questions regarding this scanning please visit the
Information Services area of http://home.vitalimages.com
____________________________________________________________ ____________



--
MySQL ODBC Mailing List
For list archives: http://lists.mysql.com/myodbc
To unsubscribe: http://lists.mysql.com/myodbc?unsub=3Dgcdmo-myodbc@m.gmane.o rg