UniverseUniversity


Home Projects Jobs Clientele Contact

uu


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: UU code



Exactly. The idea is - it shouldn't be any UPDATE or INSERT statements in your code.

Also, in SPTK you can, of course, provide parameters by injecting them into SQL. However, this slows down execution, and applies certain limits. The preferrable way is something like this:

...
CQuery qryInsert(&db,"insert into session_info select pl_id, pl_first_name || ' ' || pl_last_name from person_list where
pl_login=:login");
qryInsert.param("login") = login;
qryInsert.exec();

Also, in your example, you create a database object within th function. That creates an independent database connection. Then you work with the database, and exit the function. At the exit, the database object is destroyed closing the database connection.

Session_info is the temporary table that is created by login() stored proc. The nature of temporary tables is they exist locally in the database connection. If you establish a new database connection - it wouldn't know anything about the session_info from other database connection(s). On closing a connection, any temporary tables are discarded automatically (by the server).

So, the logic is:

1) you create a database connection somewhere at the beginning
2) you call login() stored procedure that creates and initializes session_info
3) you pass the database object to anybody who needs it
4) if you close a database connection and want to reopen it, or need another connection - start from 1)

Feel free to ask more about it (if you need so)

2007/3/8, Ilya A. Volynets-Evenbakh < ilya@total-knowledge.com>:
The problem is that you have to use stored procedures.

sergey@total-knowledge.com wrote:
> This question is to Alexey.
>
> I have a strange problem with session_info table: I can't make inserts
> work from C++. Works fine if I do it manually.
> Here is the error message that I get:
>
> Error: Exception in CODBCDatabase::queryExecute: Error while executing the
> query (non-fatal);
>
> Here is my code:
> ------------
> bool User::setSessionInfo ( std::string login) {
>  CODBCDatabase db("DSN=PostgreSQL;UID=sergey;PWD=;DATABASE=uudb");
>   try {
>     db.open();
>     CQuery qryInsert(&db,"insert into session_info select pl_id,
> pl_first_name || ' ' || pl_last_name from person_list where
> pl_login='"+login+"';");
>     qryInsert.exec();
>     db.close();
>   }
>   catch (exception& e) {
>     cout<<"\nError: " <<e.what();
>     return false;
>   }
>   return true;
> }
> -------------
>
> I did 'grant all on session_info' manually. What do you think the problem is?
> Also there is no constrain on si_person, are we going to have stored
> procedure that will do this insert/update?
>
>
>
>

--
Ilya A. Volynets-Evenbakh
Total Knowledge. CTO
http://www.total-knowledge.com




--
Alexey Parshin,
http://www.sptk.net

Authoright © Total Knowledge: 2001-2008