简体   繁体   English

C ++ OTL没有看到外部数据库更改

[英]C++ OTL doesn't see external database changes

I have a C++ program that is using OTLv4 to connecto to a database. 我有一个使用OTLv4连接数据库的C ++程序。 Everything is working fine. 一切正常。 I can both insert data into the database and read data out of the database. 我既可以将数据插入数据库,也可以从数据库中读取数据。

However, if I change data in the database from another program, then this isn't reflected in my C++ program. 但是,如果我从另一个程序更改数据库中的数据,则这不会反映在我的C ++程序中。 If I for example remove an entry with MySQL workbench, the C++ program will still see the entry. 例如,如果我使用MySQL工作台删除条目,则C ++程序仍会看到该条目。 The data I see is the data as it appeared when the program first logged in to the database. 我看到的数据是程序首次登录数据库时显示的数据。

If I log off and log on each time I do a query then I will get the current value, but that does not seem very efficient. 如果我注销并每次查询时都登录,那么我将获得当前值,但这似乎不是很有效。 Similarly if I run a query from the C++ program that will modifiy the database then the program will start seeing the current values up until that point. 同样,如果我从C ++程序运行查询,该查询将修改数据库,那么该程序将开始查看当前值。

To me this feels like some sort of over-aggressive caching, but I don't know how that works in OTL, haven't seen any mention of caches other than possibly the stream pooling which I know nothing about. 在我看来,这有点像过度激进的缓存,但是我不知道它在OTL中是如何工作的,除了我可能一无所知的流池之外,再也没有提到缓存。

I'm not doing anything fancy. 我什么都没做。 OTL is compiled with these parameters: OTL使用以下参数进行编译:

#define OTL_ODBC // Compile OTL 4.0/ODBC
#define OTL_UNICODE // Compile OTL with Unicode 
#define OTL_UNICODE_EXCEPTION_AND_RLOGON
#define OTL_UNICODE_STRING_TYPE std::wstring
// The following #define is required with MyODBC 3.51.11 and higher
#define OTL_ODBC_SELECT_STM_EXECUTE_BEFORE_DESCRIBE

The code looks something like this: 代码看起来像这样:

otl_connect::otl_initialize(1); // Multithreading
otl_connect database;
database.rlogon(...);

// Make queries with otl_stream and direct_exec
otl_stream stream(50, "select * from ...", database);
database.direct_exec("insert ... into ...", otl_exception::disabled);

database.logoff();

Is there something I have missed, some configuration I need to do? 有什么我想念的东西,需要做的一些配置吗? Turn off some sort of cache? 关闭某种缓存? Maybe i really do need to login and logoff each time? 也许我确实确实需要每次登录和注销?

I found out what is wrong: 我发现出了什么问题:

Q. OTL: When I insert a new row into a table in MySQL, I can't SELECT it, what's going on? 问:OTL:当我在MySQL的表中插入新行时,无法选择它,这是怎么回事?

If you're using a prepared SELECT statement in an otl_stream, and keep executing / reusing the statement to get new rows, you need to commit (call otl_connect::commit()) after the fetch sequence is exhausted each time. 如果您在otl_stream中使用准备好的SELECT语句,并继续执行/重用该语句以获取新行,则每次提取序列用完后,都需要提交(调用otl_connect :: commit())。 The commit call will let your MySQL Server know that your current read only transaction is finished, and the server can start a new transaction, which will make newly inserted rows to be visible to your SELECT statement. commit调用将使您的MySQL Server知道您当前的只读事务已完成,并且服务器可以启动新事务,这将使新插入的行对SELECT语句可见。 In other words, you need to commit your SELECT statements in order to able to see new rows. 换句话说,您需要提交SELECT语句才能看到新行。

From http://otl.sourceforge.net/otl3_faq.htm http://otl.sourceforge.net/otl3_faq.htm

So the problem was that whenever I make a SELECT statement I have to call otl_connect::commit(); 所以问题是,每当我执行SELECT语句时,我都必须调用otl_connect::commit(); or MySQL won't understand that the statement is finished. 否则MySQL将无法理解该语句已完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 C++ 中带有子句和函数的 oracle 的 OTL 问题 - OTL problem with oracle with clause and function in it in C++ C ++ OTL SQL数据库库是否使用参数化查询或字符串连接? - Is C++ OTL SQL database library using parameterized queries under the hood, or string concat? C ++:编译器看不到重载运算符 - C++: Compiler doesn't see overloaded operator VSCode C++ IntelliSense 看不到项目目录中的文件 - VSCode C++ IntelliSense doesn't see files in project directories C++ 应用程序 MySQL odbc 数据库连接错误:在抛出 'otl_tmpl_exception&lt;&gt; 实例后调用终止 - C++ app MySQL odbc database connection error: terminate called after throwing an instance of 'otl_tmpl_exception<> Mongo C ++客户端库看不到我的提升 - Mongo C++ Client Library Doesn't See My Boost 防止在C ++ OTL,DTL或SOCI库中进行SQL注入 - Preventing SQL injection in C++ OTL, DTL, or SOCI libraries 如何使用OTL ODBC驱动程序将C ++连接到MySQL? - How to connect C++ to MySQL with OTL ODBC driver? C ++不会通过其他方法保存更改 - C++ doesn't save the changes by other method QML GridView不能反映C ++模型中的更改 - QML GridView doesn't reflect changes in C++ model
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM