Qt issues with temporary tables, QODBC/MS SQL Server
-
wrote on 24 Oct 2011, 18:21 last edited by
Hi folks,
I'm having an issue doing anything with temporary tables within MS SQL Server while connected from Qt (4.7.3).
Here is an example piece of code, assume I am already connected:
@
QString querystr = "SELECT * INTO #TBUL1 FROM RealTable;";
querystr += "SELECT * FROM #TBUL1";
model.setQuery(querystr, database);
@It will tell me that the query is active and be without query or model errors, but there will be no data coming back to examine in the model (I've also tried doing it with a bare QSqlQuery object as well, and have attempted executing those statements individually).
When I execute this code, I am watching inside MS SQL Server Management Studio and I can even see the temporary table being created 'dbo.#TBUL1___________________' inside 'tempdb' during the session, but I don't seem to be able to do anything to the table after that.
When executing these exact statements as an isolated Query within Management Studio, I get my expected result of the 1 row currently in RealTable.
For reference, I have had no issues querying actual tables.
Thank you for reading, and I would appreciate any help!
-
wrote on 25 Oct 2011, 09:04 last edited by
-You're actually having two queries here. I suggest you split them up and execute the select for the temporary table separately.-
Sorry, I didn't read that you tried that already.
-
wrote on 25 Oct 2011, 16:45 last edited by
Thanks for the reply. It turns out I simply didn't do it properly beforehand, but making subsequent queries is a solution to manipulate temporary tables:
@
QString querystr = "SELECT * INTO #TBUL1 FROM RealTable;";
QString querystr2 = "SELECT * FROM #TBUL1;";
model.setQuery(querystr, database);
model.setQuery(querystr2, database);
@This actually does the trick.
-
wrote on 26 Oct 2011, 12:32 last edited by
Maybe just calling the first select creating the temp table can be moved to a simple [[Doc:QSqlQuery]] call. This way you would save yourself a reset on your model.
1/4