UniverseUniversity


Home Projects Jobs Clientele Contact

uu


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

Re: UU code



Guys, don't forget that database connections will be
pooled. That means there will be different requests
from _different_ users handled by the same connection.
This, in turn, means that unless someone takes care
of cleaning up the table after each request, there could
be more then one record in there.


sergey@total-knowledge.com wrote:
> Understood.
> Here is my version:
>
>   bool isValid = false;
>   try {
>     CQuery qrySelect(&db,"select si_person from session_info");
>     qrySelect.open();
>     while ( ! qrySelect.eof() ) {
>       isValid = true;
>       qrySelect.fetch();
>     }
>     qrySelect.close();
>   }
>   catch (exception& e) {
>     cout<<"\nError: " <<e.what();
>   }
>   return isValid;
>
>
> I know it's supposed to be only one record in session_info table, but
> still prefer to loop since it's a select query.
>
>
>
>   
>> Actually, the "no record test" is better to do not as:
>>
>> if (!user_id)
>>
>> but as (right after query_open()):
>>
>> if (query.eof())
>>
>> 2007/3/15, Alexey Parshin <alexeyp@gmail.com>:
>>     
>>> int user_id = 0;
>>> string user_name;
>>> try {
>>>    Query query(&db,"select si_person, si_person_name from
>>> session_info");
>>>    query.open();
>>>    user_id = query[0];
>>>    user_name = query[1];
>>>    query.close ();
>>>    if (!user_id)
>>>       throw CException("User not logged in");
>>> }
>>> catch (exception& e) {
>>>    cout << "OOPS, " << e.what() << endl;
>>> }
>>>
>>> 2007/3/15, sergey@total-knowledge.com <sergey@total-knowledge.com>:
>>>       
>>>> In order to perform authentication on each application page I need to
>>>> find
>>>> out if user with certain ID exist in session_info table.
>>>> I want to make sure that I understand how it will work, so the
>>>>         
>>> question
>>>       
>>>> is:
>>>>
>>>> 1. If session_info table exist.
>>>> AND
>>>> 2. There is a one entry there (doesn't matter what the value is).
>>>>
>>>> it means that current user is logged in.
>>>>
>>>> Is it true?
>>>>
>>>>
>>>>
>>>>
>>>>         
>>> --
>>> Alexey Parshin,
>>> http://www.sptk.net
>>>
>>>       
>>
>> --
>> Alexey Parshin,
>> http://www.sptk.net
>>
>>     
>
>
>   

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


Authoright © Total Knowledge: 2001-2008