Discussion:
[soci-users] Fwd: Dynamic query use
Medhavi Mahansaria
2015-01-02 08:34:04 UTC
Permalink
Date: 2 January 2015 2:02:35 pm IST
Subject: Dynamic query use
Hi,
I am using the below program in SOCI for executing a dynamic query.
But it is giving me ORA-24333 : zero iteration count
Please let me know where i am going wrong or should i use another approach?
Sent from my iPhone.
Brevity may be excused.
Thank You.
Regards,
Medhavi Mahansaria.
Begin forwarded
int main()
{
int id_flag=1;
int h_id=333;
int k,j;
string query,query1,query2;
session sql(oracle, "service=orcl user=TEST_POC password=TEST_POC");
try
{
query1="select id,points from test where 1=1 ";
if (id_flag == 1)
{
query2=" AND id = :h_id";
}
else
{
query2+=" AND points = :h_id";
}
query= query1+query2;
query="\""+query+"\"";
query+=",into(k),into(j),use(h_id)";
cout<<query<<endl;
statement stmt=(sql.prepare<<query);
stmt.execute();
while(stmt.fetch())
{
cout <<"the value points = "<<j<<" and id ="<<k<<endl;
}
}
catch (exception const &e)
{
cerr << "Error: " << e.what() << '\n';
}
return 0;
}
Henning Basold
2015-01-03 10:52:03 UTC
Permalink
Hi,

Think about what "into(k)" etc. are supposed to do here. You expect Soci to extract variable names from a string and use these to bind static variables in the program. This cannot work. In fact, your compiler should warn you that k and j are not initialised.

Instead ot putting the into etc. in the query string, do something like
sql.prepare << query, into(k), into(j), use(h_id);

Best,
Henning
Date: 2 January 2015 2:02:35 pm IST
Subject: Dynamic query use
Hi,
I am using the below program in SOCI for executing a dynamic query.
But it is giving me ORA-24333 : zero iteration count
Please let me know where i am going wrong or should i use another
approach?
Sent from my iPhone.
Brevity may be excused.
Thank You.
Regards,
Medhavi Mahansaria.
Begin forwarded
int main()
{
int id_flag=1;
int h_id=333;
int k,j;
string query,query1,query2;
session sql(oracle, "service=orcl user=TEST_POC
password=TEST_POC");
try
{
query1="select id,points from test where 1=1 ";
if (id_flag == 1)
{
query2=" AND id = :h_id";
}
else
{
query2+=" AND points = :h_id";
}
query= query1+query2;
query="\""+query+"\"";
query+=",into(k),into(j),use(h_id)";
cout<<query<<endl;
statement stmt=(sql.prepare<<query);
stmt.execute();
while(stmt.fetch())
{
cout <<"the value points = "<<j<<" and id ="<<k<<endl;
}
}
catch (exception const &e)
{
cerr << "Error: " << e.what() << '\n';
}
return 0;
}
------------------------------------------------------------------------
------------------------------------------------------------------------------
Dive into the World of Parallel Programming! The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is
your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more.
Take a
look and join the conversation now. http://goparallel.sourceforge.net
------------------------------------------------------------------------
_______________________________________________
soci-users mailing list
https://lists.sourceforge.net/lists/listinfo/soci-users
Medhavi Mahansaria
2015-01-09 12:14:12 UTC
Permalink
Hi,

I understand this point.. But my use and into parameters also need to be dynamic. So this method will not work.

Is there any other way to incorporate dynamic queries?

Sent from my iPhone.
Brevity may be excused.
Thank You.

Regards,
Medhavi Mahansaria.
Post by Henning Basold
Hi,
Think about what "into(k)" etc. are supposed to do here. You expect Soci to extract variable names from a string and use these to bind static variables in the program. This cannot work. In fact, your compiler should warn you that k and j are not initialised.
Instead ot putting the into etc. in the query string, do something like
sql.prepare << query, into(k), into(j), use(h_id);
Best,
Henning
Date: 2 January 2015 2:02:35 pm IST
Subject: Dynamic query use
Hi,
I am using the below program in SOCI for executing a dynamic query.
But it is giving me ORA-24333 : zero iteration count
Please let me know where i am going wrong or should i use another approach?
Sent from my iPhone.
Brevity may be excused.
Thank You.
Regards,
Medhavi Mahansaria.
Begin forwarded
int main()
{
int id_flag=1;
int h_id=333;
int k,j;
string query,query1,query2;
session sql(oracle, "service=orcl user=TEST_POC password=TEST_POC");
try
{
query1="select id,points from test where 1=1 ";
if (id_flag == 1)
{
query2=" AND id = :h_id";
}
else
{
query2+=" AND points = :h_id";
}
query= query1+query2;
query="\""+query+"\"";
query+=",into(k),into(j),use(h_id)";
cout<<query<<endl;
statement stmt=(sql.prepare<<query);
stmt.execute();
while(stmt.fetch())
{
cout <<"the value points = "<<j<<" and id ="<<k<<endl;
}
}
catch (exception const &e)
{
cerr << "Error: " << e.what() << '\n';
}
return 0;
}
Dive into the World of Parallel Programming! The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net
soci-users mailing list
https://lists.sourceforge.net/lists/listinfo/soci-users
------------------------------------------------------------------------------
Dive into the World of Parallel Programming! The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net
_______________________________________________
soci-users mailing list
https://lists.sourceforge.net/lists/listinfo/soci-users
Lalit Bhasin
2015-01-09 13:07:53 UTC
Permalink
Hi,You need to generate your query string dynamically ( as you are doing ). and then use 'soci::details::prepare_temp_type' to add ::use and ::into expressions. As an example  (courtesy : Andrew Grafham)
-clip-          std::string sql = "insert into tablename (col1, col2, col3) values (:a, :b, ;c)"; // This sql is generated programatically          soci::details::prepare_temp_type preparedStmt = dbConnection.prepare << sql;
          for (unsigned int i = 0; i < numberOfColumns; i++)              preparedStmt, use(xxxxxx); // Put in whatever you want to use here

          statement st (preparedStmt);
          st.execute();-clap-
Regards,Lalit


On Friday, January 9, 2015 9:14 PM, Medhavi Mahansaria <***@yahoo.co.in> wrote:


Hi,
I understand this point.. But my use and into parameters also need to be dynamic. So this method will not work. 
Is there any other way to incorporate dynamic queries?

Sent from my iPhone.Brevity may be excused.Thank You.
Regards,Medhavi Mahansaria.
On 03-Jan-2015, at 4:22 pm, Henning Basold <***@basold.eu> wrote:



Hi,

Think about what "into(k)" etc. are supposed to do here. You expect Soci to extract variable names from a string and use these to bind static variables in the program. This cannot work. In fact, your compiler should warn you that k and j are not initialised.

Instead ot putting the into etc. in the query string, do something like
sql.prepare << query, into(k), into(j), use(h_id);

Best,
Henning

On 2 January 2015 09:34:04 CET, Medhavi Mahansaria <***@yahoo.co.in> wrote:


Begin forwarded message:


From: Medhavi Mahansaria <***@yahoo.co.in>
Date: 2 January 2015 2:02:35 pm IST
To: "soci-users-***@lists.sourceforge.net" <soci-users-***@lists.sourceforge.net>
Subject: Dynamic query use



Hi, 
I am using the below program in SOCI for executing a dynamic query.
But it is giving me ORA-24333 : zero iteration count
Please let me know where i am going wrong or should i use another approach?

Sent from my iPhone.Brevity may be excused.ThankYou.
Regards,Medhavi Mahansaria.
Begin forwarded 




int main()
{
        int id_flag=1;
        int h_id=333;
        int k,j;
        string query,query1,query2;
        sessionsql(oracle, "service=orcl user=TEST_POC password=TEST_POC");

     try
     {
        query1="selectid,points from test where 1=1 ";
        if (id_flag== 1)
        {
            query2=" AND id = :h_id";
        }
        else
        {
           query2+=" AND points = :h_id";
        }
        query= query1+query2;
        query="\""+query+"\"";
        query+=",into(k),into(j),use(h_id)";

        cout<<query<<endl;
        statementstmt=(sql.prepare<<query);
        stmt.execute();
        while(stmt.fetch())
        {
            cout <<"the value points = "<<j<<"and id ="<<k<<endl;
        }

    }
    catch (exception const&e)
    {
        cerr <<"Error: " << e.what() << '\n';
    }

    return 0;

}




Dive into the World of Parallel Programming! The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net
soci-users mailing list
soci-***@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/soci-users


------------------------------------------------------------------------------
Dive into the World of Parallel Programming! The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net

_______________________________________________
soci-users mailing list
soci-***@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/soci-users
Lalit Bhasin
2015-01-11 02:10:41 UTC
Permalink
Hi,
You need to generate your query string dynamically ( as you are doing ). and then use 'soci::details::prepare_temp_type' to add ::use and ::into expressions.
As an example (courtesy : Andrew Grafham)

-clip-
std::string sql = "insert into tablename (col1, col2, col3) values (:a, :b, ;c)"; // This sql is generated programatically
soci::details::prepare_temp_type preparedStmt = dbConnection.prepare << sql;

for (unsigned int i = 0; i < numberOfColumns; i++)
preparedStmt, use(xxxxxx); // Put in whatever you want to use here


statement st (preparedStmt);

st.execute();
-clap-

Regards,
Lalit

Sent from my iPhone
Post by Medhavi Mahansaria
Hi,
I understand this point.. But my use and into parameters also need to be dynamic. So this method will not work.
Is there any other way to incorporate dynamic queries?
Sent from my iPhone.
Brevity may be excused.
Thank You.
Regards,
Medhavi Mahansaria.
Post by Henning Basold
Hi,
Think about what "into(k)" etc. are supposed to do here. You expect Soci to extract variable names from a string and use these to bind static variables in the program. This cannot work. In fact, your compiler should warn you that k and j are not initialised.
Instead ot putting the into etc. in the query string, do something like
sql.prepare << query, into(k), into(j), use(h_id);
Best,
Henning
Date: 2 January 2015 2:02:35 pm IST
Subject: Dynamic query use
Hi,
I am using the below program in SOCI for executing a dynamic query.
But it is giving me ORA-24333 : zero iteration count
Please let me know where i am going wrong or should i use another approach?
Sent from my iPhone.
Brevity may be excused.
Thank You.
Regards,
Medhavi Mahansaria.
Begin forwarded
int main()
{
int id_flag=1;
int h_id=333;
int k,j;
string query,query1,query2;
session sql(oracle, "service=orcl user=TEST_POC password=TEST_POC");
try
{
query1="select id,points from test where 1=1 ";
if (id_flag == 1)
{
query2=" AND id = :h_id";
}
else
{
query2+=" AND points = :h_id";
}
query= query1+query2;
query="\""+query+"\"";
query+=",into(k),into(j),use(h_id)";
cout<<query<<endl;
statement stmt=(sql.prepare<<query);
stmt.execute();
while(stmt.fetch())
{
cout <<"the value points = "<<j<<" and id ="<<k<<endl;
}
}
catch (exception const &e)
{
cerr << "Error: " << e.what() << '\n';
}
return 0;
}
Dive into the World of Parallel Programming! The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net
soci-users mailing list
https://lists.sourceforge.net/lists/listinfo/soci-users
------------------------------------------------------------------------------
Dive into the World of Parallel Programming! The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net
_______________________________________________
soci-users mailing list
https://lists.sourceforge.net/lists/listinfo/soci-users
------------------------------------------------------------------------------
Dive into the World of Parallel Programming! The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net
_______________________________________________
soci-users mailing list
https://lists.sourceforge.net/lists/listinfo/soci-users
Loading...