Skip to content

Add ODBC DirectExec public API#3502

Merged
aleks-f merged 8 commits intopocoproject:develfrom
xakod:feature/odbc-exec-direct
Mar 22, 2023
Merged

Add ODBC DirectExec public API#3502
aleks-f merged 8 commits intopocoproject:develfrom
xakod:feature/odbc-exec-direct

Conversation

@xakod
Copy link
Copy Markdown
Contributor

@xakod xakod commented Jan 24, 2022

It was a very long story how i couldn't determine why temp tables dont work in Poco between statements (#3499). After all, I compared how Poco use ODBC api and NanoODBC
For 1 single statement Poco call stack (except attrs and some non-related things):

SQLAllocHandle
SQLPrepareW
SQLNumResultCol
SQLExecute
SQLFetch
SQLRowCount
SQLFreeHandle

For 1 single statement NanoODBC call stack (except attrs and some non-related things):

SQLAllocHandle
SQLExecDirect
SQLNumResultCol
SQLCancel
SQLFreeStmt
SQLFreeHandle

Looks like Poco uses only prepared statement while nanodbc calls execute direct every time. I tried to investigate deeper and deeper. If I create temp table with prepared statement, temp table will not be available in the next statement. How it works with sessions but with statements. But if I create temp table with direct execute, it will be available in the statements...
So I tried to add direct execute to Poco but I dont understand well Poco architecture and it needs to change a lot of classes and maybe architecture too. So I create this PR as proposal or draft.
If you provide me some help I'll be very thankful.

Closes #3499

MS mention this in docs https://learn.microsoft.com/en-us/sql/relational-databases/native-client-odbc-queries/executing-statements/prepared-execution?view=sql-server-ver16
Prepared statements cannot be used to create temporary objects on SQL Server.

auto data=&query.at(0);
SQLCHAR * statementText=reinterpret_cast<unsigned char*>(data);
SQLINTEGER textLength=query.size();
SQLRETURN rc = SQLExecDirect(_stmt,statementText,textLength);
Copy link
Copy Markdown

@dedlocc dedlocc Jan 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Add spaces around = and after commas.
  2. Better use query.data() instead of &query.at(0) and then there's no need of a separate variable.
  3. Even though it seems you do need to pass a non-const char pointer to SQLExecDirect, you don't need it for every possible implementation of this method (e.g. in StatementImpl::execDirectImpl). So I'd suggest passing it as const reference and only make a copy if needed.
  4. * should be a part of type (so no whitespace before it), as suggested here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xakod xakod force-pushed the feature/odbc-exec-direct branch 2 times, most recently from 2039682 to 32949be Compare January 24, 2022 14:49
@obiltschnig obiltschnig added this to the Release 1.12.0 milestone Feb 11, 2022
@xakod xakod force-pushed the feature/odbc-exec-direct branch from 430296d to a23a419 Compare September 6, 2022 09:33
@xakod xakod force-pushed the feature/odbc-exec-direct branch from a23a419 to dc6a9c8 Compare September 6, 2022 09:37
@xakod
Copy link
Copy Markdown
Contributor Author

xakod commented Oct 8, 2022

@aleks-f sorry for ping, but are there any chances for this pr?

@aleks-f
Copy link
Copy Markdown
Member

aleks-f commented Mar 17, 2023

@Jihadist yes, but there are still some unanswered questions above

@xakod
Copy link
Copy Markdown
Contributor Author

xakod commented Mar 17, 2023

@Jihadist yes, but there are still some unanswered questions above

If you mean async part, I don't know how to implement it. Maybe you can suggest something

@aleks-f
Copy link
Copy Markdown
Member

aleks-f commented Mar 18, 2023

@Jihadist yes, but there are still some unanswered questions above

If you mean async part, I don't know how to implement it. Maybe you can suggest something

I did suggest something, you just have to read it

image

@xakod
Copy link
Copy Markdown
Contributor Author

xakod commented Mar 18, 2023

@aleks-f it sounds strange, but I don't see anything
изображение

@xakod xakod force-pushed the feature/odbc-exec-direct branch from 8c01569 to 094ebfb Compare March 20, 2023 09:08
@aleks-f aleks-f merged commit 93d1816 into pocoproject:devel Mar 22, 2023
aleks-f pushed a commit that referenced this pull request Nov 27, 2023
* ODBC sqlDirectExec

* doc

* Small fix

* Fix tabs, add missing const, fix style

* Add test case

* Small fixes

* suggested fix for async

* test for returned values
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ODBC Driver: temp tables

5 participants