我试图将C++连接到MySql,但无法正常工作。我从Oracle网站使用Windows的最新MySql和C++/Connector。我也使用VS2010。
它可以编译,并且除了getString之外,其他所有方法都可以正常工作!我使用了他们提供的一些调整示例:
#include "stdafx.h"
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <stdexcept>
#include <driver/mysql_public_iface.h>
#include "examples.h"
using namespace std;
int main(int argc, const char **argv)
{
string url(argc >= 2 ? argv[1] : EXAMPLE_HOST);
const string user(argc >= 3 ? argv[2] : EXAMPLE_USER);
const string pass(argc >= 4 ? argv[3] : EXAMPLE_PASS);
const string database(argc >= 5 ? argv[4] : EXAMPLE_DB);
/* sql::ResultSet.rowsCount() returns size_t */
size_t row;
stringstream sql;
stringstream msg;
int i, affected_rows;
cout << boolalpha;
cout << "1..1" << endl;
cout << "# Connector/C++ connect basic usage example.." << endl;
cout << "#" << endl;
try {
sql::Driver * driver = sql::mysql::get_driver_instance();
/* Using the Driver to create a connection */
std::auto_ptr< sql::Connection > con(driver->connect("localhost", "root", "root"));
/* Creating a "simple" statement - "simple" = not a prepared statement */
std::auto_ptr< sql::Statement > stmt(con->createStatement());
/* Create a test table demonstrating the use of sql::Statement.execute() */
stmt->execute("USE publications");
cout << "#\t Test table created" << endl;
/* Populate the test table with data */
cout << "#\t Test table populated" << endl;
{
/*
Run a query which returns exactly one result set like SELECT
Stored procedures (CALL) may return more than one result set
*/
std::auto_ptr< sql::ResultSet > res(stmt->executeQuery("SELECT id, task FROM to_do_list ORDER BY id ASC"));
cout << "#\t Running 'SELECT id, task FROM to_do_list ORDER BY id ASC'" << endl;
/* Number of rows in the result set */
cout << "#\t\t Number of rows\t";
cout << "res->rowsCount() = " << res->rowsCount() << endl;
if (res->rowsCount() != EXAMPLE_NUM_TEST_ROWS) {
msg.str("");
msg << "Expecting " << EXAMPLE_NUM_TEST_ROWS << "rows, found " << res->rowsCount();
throw runtime_error(msg.str());
}
/* Fetching data */
row = 0;
while (res->next()) {
cout << "#\t\t Fetching row " << row << "\t";
/* You can use either numeric offsets... */
cout << "id = " << res->getInt("id");
/* ... or column names for accessing results. The latter is recommended. */
cout << ", task = '" << res->getString("task") << "'" << endl;
row++;
system("PAUSE");
}
}
1..1
# Connector/C++ connect basic usage example..
#
# Test table created
# Test table populated
# Running 'SELECT id, task FROM to_do_list ORDER BY id ASC'
# Number of rows res->rowsCount() = 4
# Fetching row 0 id = 3, task = ''
Press any key to continue . . .
# Fetching row 1 id = 7, task = ''
Press any key to continue . . .
☼ Ñ╤½x R= I> ☼ £I> task ↕ 4å@ xQ@ ♦ ☼ ☻ ocalhost ½xÇ
'
Press any key to continue . . .
mysql> use publications
Database changed
mysql> select id, task from to_do_list;
+----+---------------------------+
| id | task |
+----+---------------------------+
| 9 | prepare for calculus |
| 3 | buy jeans |
| 8 | buy new scale |
| 7 | buy Ethics book for class |
+----+---------------------------+
4 rows in set (0.00 sec)
msvcp90d.dll!104e8dcb()
[Frames below may be incorrect and/or missing, no symbols loaded for msvcp90d.dll]
try_mysql_native.exe!std::operator<<(std::basic_ostream > & os={...}, const sql::SQLString & str={...}) Line 196 + 0x1f bytes C++ try_mysql_native.exe!main(int argc=1, const char * * argv=0x003e63e8) Line 115 + 0xa5 bytes C++ try_mysql_native.exe!__tmainCRTStartup() Line 586 + 0x19 bytes C try_mysql_native.exe!mainCRTStartup() Line 403 C kernel32.dll!7c817077()
最佳答案
您确定任务栏没有设置二进制排序规则吗?如果是这样,连接器可能会为同一列返回不同的元数据。
更新:
另外,请检查连接器是否已使用与项目相同的运行时进行编译。如果使用VS,我敢打赌另一个是用/MT编译的,另一个是用/MD编译的。这样,他们使用不同的堆,将无法正常工作。
关于c++ - MySql C++连接器getString()不能正常工作,而getInt可以正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4822958/
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t
我的瘦服务器配置了nginx,我的ROR应用程序正在它们上运行。在我发布代码更新时运行thinrestart会给我的应用程序带来一些停机时间。我试图弄清楚如何优雅地重启正在运行的Thin实例,但找不到好的解决方案。有没有人能做到这一点? 最佳答案 #Restartjustthethinserverdescribedbythatconfigsudothin-C/etc/thin/mysite.ymlrestartNginx将继续运行并代理请求。如果您将Nginx设置为使用多个上游服务器,例如server{listen80;server
我正在使用Sequel构建一个愿望list系统。我有一个wishlists和itemstable和一个items_wishlists连接表(该名称是续集选择的名称)。items_wishlists表还有一个用于facebookid的额外列(因此我可以存储opengraph操作),这是一个NOTNULL列。我还有Wishlist和Item具有续集many_to_many关联的模型已建立。Wishlist类也有:selectmany_to_many关联的选项设置为select:[:items.*,:items_wishlists__facebook_action_id].有没有一种方法可以
我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳
关闭。这个问题需要detailsorclarity.它目前不接受答案。想改进这个问题吗?通过editingthispost添加细节并澄清问题.关闭8年前。Improvethisquestion在首页我有:汽车:VolvoSaabMercedesAudistatic_pages_spec.rb中的测试代码:it"shouldhavetherightselect"dovisithome_pathit{shouldhave_select('cars',:options=>['volvo','saab','mercedes','audi'])}end响应是rspec./spec/request
在Rails4.0.2中,我使用s3_direct_upload和aws-sdkgems直接为s3存储桶上传文件。在开发环境中它工作正常,但在生产环境中它会抛出如下错误,ActionView::Template::Error(noimplicitconversionofnilintoString)在View中,create_cv_url,:id=>"s3_uploader",:key=>"cv_uploads/{unique_id}/${filename}",:key_starts_with=>"cv_uploads/",:callback_param=>"cv[direct_uplo
我使用的是Firefox版本36.0.1和Selenium-Webdrivergem版本2.45.0。我能够创建Firefox实例,但无法使用脚本继续进行进一步的操作无法在60秒内获得稳定的Firefox连接(127.0.0.1:7055)错误。有人能帮帮我吗? 最佳答案 我遇到了同样的问题。降级到firefoxv33后一切正常。您可以找到旧版本here 关于ruby-无法在60秒内获得稳定的Firefox连接(127.0.0.1:7055),我们在StackOverflow上找到一个类
GivenIamadumbprogrammerandIamusingrspecandIamusingsporkandIwanttodebug...mmm...let'ssaaay,aspecforPhone.那么,我应该把“require'ruby-debug'”行放在哪里,以便在phone_spec.rb的特定点停止处理?(我所要求的只是一个大而粗的箭头,即使是一个有挑战性的程序员也能看到:-3)我已经尝试了很多位置,除非我没有正确测试它们,否则会发生一些奇怪的事情:在spec_helper.rb中的以下位置:require'rubygems'require'spork'
使用Ruby1.9.2运行IDE提示说需要gemruby-debug-base19x并提供安装它。但是,在尝试安装它时会显示消息Failedtoinstallgems.Followinggemswerenotinstalled:C:/ProgramFiles(x86)/JetBrains/RubyMine3.2.4/rb/gems/ruby-debug-base19x-0.11.30.pre2.gem:Errorinstallingruby-debug-base19x-0.11.30.pre2.gem:The'linecache19'nativegemrequiresinstall