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 
<[email protected]> 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 <[email protected]> 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 <[email protected]> 
wrote:


Begin forwarded message:


From: Medhavi Mahansaria <[email protected]>
Date: 2 January 2015 2:02:35 pm IST
To: "[email protected]" 
<[email protected]>
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
[email protected]
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
[email protected]
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
[email protected]
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/soci-users

Reply via email to