Project

General

Profile

problems reading tables immediately after creating them - MySQL backend

Added by John Davidson almost 10 years ago

Is there something you should do to a MySQL database session/connection/connectionpool after you create a db schema with session.createTables()? Like, close the session and re-open it, or something?

I ask because if I createTables() and write to them in the same session, then the first time I read from them in that same session I get an exception thrown by

Wt::Dbo::sql_value_traits<Wt::WString,void>::type(Wt::Dbo::SqlConnection * conn, int size) Line 197 C++

which is this:

if (size == -1)
   return std::string(conn->textType()) + " not null"; <<<<<================ throws exception
else
   return "varchar(" + boost::lexical_cast<std::string>(size) + ") not null";
}

suggesting the connection has been lost, or something?

I never get that exception any other time. If I createTables() and write to them in the one session, and then restart the program, it reads the tables without error. So it seems to be something to do with needing to restart the session or connection or connectionpool or something.

What am I failing to do after createTables()?

thanks

John

PS Possibly related: I have structured my dB, complete with its connection, connectionpool and session, as a single global object that each web client accesses. It has a scheduler and needs to keep working long after all the web clients have closed, you see.

But I wonder whether the session should be created afresh by each web client? It would mean using extra memory per client, which is why I avoided it, but something about my structure feels wrong to me. Is a session a per-client thing, or a per-database-connection thing?


Replies (2)

RE: problems reading tables immediately after creating them - MySQL backend - Added by Saif Rehman almost 10 years ago

I believe you should not use the same Dbo::Session between multiple clients(WApplication)

But if you must share it then you should use mutexes.

Also, according to Koen, Dbo::Session(s) are not very expensive to create for each WApplcation.

    (1-2/2)