Hi all,

I have another n00b question. It's regarding reading queries from file. 
I can imagine several ways to go about this. In the docs it does mention it:

"First, you don't need to use SQL queries as string literals. In bigger 
projects it is a common practice to store SQL queries externally (in a 
file, or in a... database) and load them before use. This means that 
they are not necessarily expected to appear in the program code, as they 
do in our simple code examples and the advantage of separating them from 
the source code of the main program is, among others, the possibility to 
optimize and tune the SQL queries without recompilation and relinking of 
the whole program."

Which is the main reason I'm looking to do this.

If it is a simple query all contained in a static string, then it's very 
straight forward. However, when the are variables involved, where 
clauses for example, then it's a bit more involved.

I was thinking about storing each part of the query on a separate line. 
Say I have the following code (not real):

     stringstream query;

     query << "select roomid, from rooms where type = 3 and standard not 
in (9, 10) and roomid not in (select room from roomsOccupied where ";

     if (roomList.size() > 0)
     {
         query << "room in (";
         int rooms = roomList.size();
         for (int i = 0; i > rooms; i++)
         {
             query << roomList[i];
             if (i < rooms - 1) query << ", ";
         }
         query << ") and ";
     }
     query << "beds = 2";

     session mssql(odbc, connectString);
     mssql << query.str(), into(buffer);

I would put each string in a file on a separate line. Read this file 
line by line and use those strings in the above code.

Does that sound like a good way to go about it? Any other suggestions?

I don't relish recompiling code when I've made a spelling mistake in my 
query or the DB has changed.

Thanks for the advice,

Simon

-- 
simonsmicrophone.com

------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Soci-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/soci-users

Reply via email to