当前位置: 首页>>代码示例>>C++>>正文


C++ MySQL类代码示例

本文整理汇总了C++中MySQL的典型用法代码示例。如果您正苦于以下问题:C++ MySQL类的具体用法?C++ MySQL怎么用?C++ MySQL使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了MySQL类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: f_mysql_async_query_result

Variant f_mysql_async_query_result(CVarRef link_identifier) {
  MySQL* mySQL = MySQL::Get(link_identifier);
  if (!mySQL) {
    raise_warning("supplied argument is not a valid MySQL-Link resource");
    return Variant(Variant::NullInit());
  }
  MYSQL* conn = mySQL->get();
  if (!conn || (conn->async_op_status != ASYNC_OP_QUERY &&
                conn->async_op_status != ASYNC_OP_UNSET)) {
    raise_warning("runtime/ext_mysql: attempt to check query result when query "
                  "not executing");
    return Variant(Variant::NullInit());
  }

  int error = 0;
  auto status = mysql_real_query_nonblocking(
    conn, mySQL->m_async_query.data(), mySQL->m_async_query.size(), &error);

  if (status != NET_ASYNC_COMPLETE) {
    return Variant(Variant::NullInit());
  }

  if (error) {
    return Variant(Variant::NullInit());
  }

  mySQL->m_async_query.reset();

  MYSQL_RES* mysql_result = mysql_use_result(conn);
  MySQLResult *r = NEWOBJ(MySQLResult)(mysql_result);
  r->setAsyncConnection(mySQL);
  Resource ret(r);
  return ret;
}
开发者ID:Bluarggag,项目名称:hhvm,代码行数:34,代码来源:ext_mysql.cpp

示例2: Get

bool MySQL::CloseConn(const Variant& link_identifier) {
  MySQL *mySQL = Get(link_identifier);
  if (mySQL && !mySQL->isPersistent()) {
    mySQL->close();
  }
  return true;
}
开发者ID:2bj,项目名称:hhvm,代码行数:7,代码来源:mysql_common.cpp

示例3: main

int main ( ) {
	/* Create MySQL object */
	MySQL sql;
	
	/* Open Database */
	std::cout << "Connecting to 'localhost' using 'test' database" << std::endl;
	assert ( sql.connect ( "localhost", "root", "blue23", "test" ) == true );
	std::cout << "Opening was successful" << std::endl;	

	/* Create a table */		
	std::cout << "Creating table tbl1 (one int, two int)" << std::endl;
	assert ( sql.exec ( "create table tbl1 (one int, two int);" ) == 1 );
	std::cout << "Created table tbl1" << std::endl;
	
	/* Insert values */
	std::cout << "Insert values ( 10, 10 ) into tbl1" << std::endl; 
	assert ( sql.exec ( "insert into tbl1 (one, two) VALUES ( 10, 10 )" ) == 1 );
	std::cout << "Inserted values successfully" << std::endl;

	/* Query values */
	std::cout << "Query values to make sure of integraty" << std::endl;
	assert ( sql.query ( "select * from tbl1" ) == 1);
	std::cout << "Query was successful" << std::endl;
	
	/* Integraty of values */
	std::cout << "Checking to see if query returned results" << std::endl;
	assert ( sql.hasNext ( ) );
	std::cout << "Results were returned" << std::endl;

	/* Check to see that we get a total of two columns ( one, two ) from query */
	std::cout << "Checking to see if a record has two entries ( one, two )" << std::endl;
	std::vector<std::string> l = sql.next ( );
	assert( l.size() == 2 );
	std::cout << "Integraty was achieved for record count" << std::endl;
	
	/* Check Integraty of inserted row ( 10, 10 ) */
	std::cout << "Checking to see one = 10" << std::endl;
	assert( l[0].compare ( "10" ) == 0 );
	std::cout << "Checking to see two = 10" << std::endl; 
	assert( l[1].compare ( "10" ) == 0 );
	
	/* Clear out values */
	std::cout << "Clearing values from database" << std::endl;
	assert ( sql.query ( "delete from tbl1" ) == 1 );
	std::cout << "Database values were cleared" << std::endl;
	
	/* Remove table */
	std::cout << "Removing table tbl1 from database" << std::endl;
	assert ( sql.query ( "DROP TABLE IF EXISTS tbl1" ) == 1);
	std::cout << "Table tbl1 was removed from database" << std::endl;

	/* Close database */
	std::cout << "Database attempting to close" << std::endl;
	sql.disconnect ();
	std::cout << "Database closed" << std::endl;
	
	/* Closing statements */
	std::cout << "Finished unit testing :D" << std::endl;
	return 1;	
};
开发者ID:RodolfoSilva,项目名称:scribble-websocket-server,代码行数:60,代码来源:unit_mysql.cpp

示例4: f_mysql_async_status

int64_t f_mysql_async_status(CVarRef link_identifier) {
  MySQL *mySQL = MySQL::Get(link_identifier);
  if (!mySQL || !mySQL->get()) {
    raise_warning("supplied argument is not a valid MySQL-Link resource");
    return -1;
  }

  return mySQL->get()->async_op_status;
}
开发者ID:Bluarggag,项目名称:hhvm,代码行数:9,代码来源:ext_mysql.cpp

示例5: HHVM_FUNCTION

static int64_t HHVM_FUNCTION(mysql_async_status,
                             const Variant& link_identifier) {
  MySQL *mySQL = MySQL::Get(link_identifier);
  if (!mySQL || !mySQL->get()) {
    raise_warning("supplied argument is not a valid MySQL-Link resource");
    return -1;
  }

  return mySQL->get()->async_op_status;
}
开发者ID:CodeKong,项目名称:hhvm,代码行数:10,代码来源:ext_mysql.cpp

示例6: f_mysql_warning_count

Variant f_mysql_warning_count(CVarRef link_identifier /* = null */) {
  MySQL *mySQL = MySQL::Get(link_identifier);
  if (!mySQL) {
    raise_warning("supplied argument is not a valid MySQL-Link resource");
    return false;
  }
  MYSQL *conn = mySQL->get();
  if (conn) {
    return (int64_t)mysql_warning_count(conn);
  }
  return false;
}
开发者ID:Bluarggag,项目名称:hhvm,代码行数:12,代码来源:ext_mysql.cpp

示例7: ajaxIsEmailExist

void UserModule::ajaxIsEmailExist(WebPage *page, HttpRequest &request) {
	MySQL *query = manager->newQuery();

	String email = request.header.POST.getValue("email");
	String sql = (String)"select id from users where (email='" + email + "')";
	string sql8 = sql.to_string();
	if (query->active(sql) > 0) {
		page->tplIndex->out("out", "<note>\n<result>1</result></note>\n");
	}

	manager->deleteQuery(query);
}
开发者ID:sitev,项目名称:cjCms,代码行数:12,代码来源:userModule.cpp

示例8: MySQL

MySQL* ConnectionPool::init_connect() {
	MySQL *query = new MySQL();
	if (!query->init()) {
		printf("!query->init()\n");
		return NULL;
	}
	if (!query->connect("127.0.0.1", "root", "", "sitev")) {
		printf("!query->connect()\n");
		return NULL;
	}
	query->exec("SET NAMES utf8");
	return query;
}
开发者ID:sitev,项目名称:cjCms,代码行数:13,代码来源:connectionPool.cpp

示例9: paintPageWidgets

void WidgetManager::paintPageWidgets(WebPage *page) {
	if (page == NULL) return;

	MySQL *query = page->site->manager->newQuery();
	String sql = "select widgetId, tag from widget_site where siteId='" + (String)page->site->siteId + "'";
	if (query->active(sql)) {
		int count = query->getRowCount();
		for (int i = 0; i < count; i++) {
			int widgetId = query->getFieldValue(i, "widgetId").toInt();
			String tag = query->getFieldValue(i, "tag");
			paintWidget(page, tag, widgetId);
		}
	}
}
开发者ID:VasiliyChuvak,项目名称:cjCms,代码行数:14,代码来源:widget.cpp

示例10: getModuleUrl

String WebModule::getModuleUrl() {
	MySQL *query = manager->newQuery();

	String sql = "select * from modules where id='" + (String)moduleId + "'";
	if (query->exec(sql)) {
		if (query->storeResult()) {
			int count = query->getRowCount();
			if (count > 0) {
				String url = query->getFieldValue(0, "url");
				return url;
			}
		}
	}
	return "";
}
开发者ID:VasiliyChuvak,项目名称:cjCms,代码行数:15,代码来源:webModule.cpp

示例11: f_mysql_errno

Variant f_mysql_errno(const Variant& link_identifier /* = null */) {
  MySQL *mySQL = MySQL::Get(link_identifier);
  if (!mySQL) {
    raise_warning("supplied argument is not a valid MySQL-Link resource");
    return false;
  }
  MYSQL *conn = mySQL->get();
  if (conn) {
    return (int64_t)mysql_errno(conn);
  }
  if (mySQL->m_last_error_set) {
    return (int64_t)mySQL->m_last_errno;
  }
  return false;
}
开发者ID:isgiker,项目名称:hhvm,代码行数:15,代码来源:ext_mysql.cpp

示例12: f_mysql_error

Variant f_mysql_error(CVarRef link_identifier /* = null */) {
  MySQL *mySQL = MySQL::Get(link_identifier);
  if (!mySQL) {
    raise_warning("supplied argument is not a valid MySQL-Link resource");
    return false;
  }
  MYSQL *conn = mySQL->get();
  if (conn) {
    return String(mysql_error(conn), CopyString);
  }
  if (mySQL->m_last_error_set) {
    return String(mySQL->m_last_error);
  }
  return false;
}
开发者ID:Bluarggag,项目名称:hhvm,代码行数:15,代码来源:ext_mysql.cpp

示例13: paint

void StaticPageModule::paint(WebPage *page, HttpRequest &request) {
	MySQL *query = manager->newQuery();


	String sql = "select txt.value from data d, dataText txt where d.dataId=txt.id and d.pageId='" + (String)page->pageId + "'";
	printf("sql = %s\n", sql.toString8().c_str());
	if (query->exec(sql)) {
		if (query->storeResult()) {
			int count = query->getRowCount();
			if (count > 0)  {
				String content = query->getFieldValue(0, "value");
				page->out("content", content);
			}
		}
	}
}
开发者ID:VasiliyChuvak,项目名称:cjCms,代码行数:16,代码来源:webModule.cpp

示例14: ajax

void NewsModule::ajax(WebPage *page, HttpRequest &request) {
	MySQL *query = manager->newQuery();
	String obj = request.header.GET.getValue("p1");
	String func = request.header.GET.getValue("p2");
	String uuid = request.header.COOKIE.getValue("uuid");

	if (obj == "post") {
		if (func == "sendComment") {
			String comment = request.header.POST.getValue("comment");
			int newsId = request.header.POST.getValue("newsId").toInt();
			int userId = manager->getUserId(uuid);
			String result = "";

			String sql = "insert into comments (userId, newsId, comment) values ('" + (String)userId + "', '" + (String)newsId + "', '" + comment + "')";
			if (query->exec(sql)) {
				result = "1";
			}

			page->tplIndex->out("out", "<note>\n");
			page->tplIndex->out("out", "<result>" + result + "</result>\n");
			page->tplIndex->out("out", "</note>\n");
		}
		if (func == "sendPost") {
			String name = request.header.POST.getValue("name");
			String text = request.header.POST.getValue("content");
			text = request.header.htmlEntitiesDecode(text.toString8());
			int userId = manager->getUserId(uuid);
			String result = "";

			String sql = "insert into dataNews (name, text) values ('" + name + "', '" + text + "')";
			if (query->exec(sql)) {
				sql = "insert into data (pageId, dataId, moduleId, userId) values('" + (String)page->pageId + "', LAST_INSERT_ID(), '3', '" + (String)userId + "')";
				if (query->exec(sql)) {
					result = "1";
				}
				else result = "3";
			}
			else result = "2";
			page->tplIndex->out("out", "<note>\n");
			page->tplIndex->out("out", "<result>" + result + "</result>\n");
			page->tplIndex->out("out", "<sql>" + sql + "</sql>\n");
			page->tplIndex->out("out", "</note>\n");
		}
	}
}
开发者ID:VasiliyChuvak,项目名称:cjCms,代码行数:45,代码来源:webModule.cpp

示例15: activate

void UserModule::activate(WebPage *page, HttpRequest &request) {
	MySQL *query = manager->newQuery();
	String p3 = request.header.GET.getValue("p3");
	String sql = "update users set active = '1', password=newPassword where uuid = '" + p3 + "'";
	WebTemplate * tpl = new WebTemplate();
	String activateTpl = "";
	if (query->exec(sql)) {
		activateTpl = "activateSuccess_tpl.html";
	}
	else {
		activateTpl = "activateFail_tpl.html";
	}
	if (tpl->open(manager->modulePath + "/user/" + activateTpl)) {
		tpl->exec();
		page->out("content", tpl->html);
	}
	manager->deleteQuery(query);
}
开发者ID:sitev,项目名称:cjCms,代码行数:18,代码来源:userModule.cpp


注:本文中的MySQL类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。