Hi,
In my first exemple, row is updated each time fetch is called and it
doesn't not contains all resulting rows. This is the same in the second
example: m_name and ystr are updated on each fetch call.
Developer has to take care of column type. When you are using soci::row,
if you do not give correct type, row.get or row.operator>> will raise an
exception.
If you don't know the type in advance you can use
row.get_properties(col_id).get_data_type() to retrieve it dynamically.
Arnaud
On 12/07/2015 13:48, Sonya Blade wrote:
Hi,
Thanks in advance, I noticed that statement section in soci web site
rowset seems what I need but your solution is
elegant also, running quick eye in your example: I didn't know that
resulting row can contain more than one row in
your code you actually iterate through all the rows contained in row
object. Does my code interpretation is correct ?
I'd like to know also that who is reponsible for type checking, for
example what about if the 3rd column in row is not double , does it
require
of developer to know that before hand ?
Regards,
------------------------------------------------------------------------
Date: Sun, 12 Jul 2015 13:36:33 +0200
From: [email protected]
To: [email protected]
Subject: Re: [soci-devel] How to iterate through rows of resulting
database.
Hi,
You can use statement to iterate over all rows (see
http://soci.sourceforge.net/doc/3.2/statements.html):
int main()
{
session sql(firebird, "service=D:/New_DB.FDB user=SYSDBA
password=masterkey");
row r;
std::string m_name;
double ystr;
soci::statement stmt = (sql.prepare << "select * from materials",
into(r));
stmt.execute(false); // false to not fetch any data until loop
while(stmt.fetch())
{
r >> m_name >> ystr >> ystr;
cout << "Hello world!" << endl;
}
return 0;
}
Or, without soci::row
int main()
{
session sql(firebird, "service=D:/New_DB.FDB user=SYSDBA
password=masterkey");
std::string m_name;
double ystr;
soci::statement stmt = (sql.prepare << "select * from materials",
into(m_name), into(ystr), into(ystr));
stmt.execute(false); // false to not fetch any data until loop
while(stmt.fetch())
{
std::cout << "m_name: " << m_name << "; ystr = " << ystr <<
std::endl;
}
return 0;
}
Arnaud
On 12/07/2015 09:08, Sonya Blade wrote:
Hi All,
I'd like to know how one is supposeed to iterate through rows of
resulting database. For example if I have
following code the resulting dataset is returned into r (row)
variable, but I don't know how iterate through it.
Any help will be appreicated,
Regards,
int main()
{
session sql(firebird, "service=D:/New_DB.FDB user=SYSDBA
password=masterkey");
row r;
sql << "select * from materials", into(r);
std::string m_name;
double ystr;
r >> m_name >> ystr >> ystr;
cout << "Hello world!" << endl;
return 0;
}
------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
soci-devel mailing list
[email protected] <mailto:[email protected]>
https://lists.sourceforge.net/lists/listinfo/soci-devel
------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud. GigeNET's Cloud
Solutions provide you with the tools and support that you need to
offload your IT needs and focus on growing your business. Configured
For All Businesses. Start Your Cloud Today. https://www.gigenetcloud.com/
_______________________________________________ soci-devel mailing
list [email protected]
https://lists.sourceforge.net/lists/listinfo/soci-devel
------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
soci-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/soci-devel
------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
soci-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/soci-devel