实例讲解如何使用C++操作MySQL数据库类
用C++操作MySQL数据库类:
注释:这几个类对处理不是很大数据量的操作是很理想的, 但不适宜特大型的数据的查询,因为源码中将查询到的数据直接放入了内存。
/*
* project:
* 通用模块 ( 用 c++ 处理 mysql 数据库类,像ADO )
*
* description:
*
* 通过DataBase,RecordSet,Record,Field类,实现对mysql数据库的操作
* 包括连接、修改、添加、删除、查询等等,像ADO一样操作数据库,使
* 用方便
*
* ( the end of this file have one sample,
* welcom to use... )
*
*
* file:zlb_mysql.h
*
* author: @ zlb
*
* time:2005-12-12
*
*
*
--*/
#ifndef ZLB_MYSQL_H
#define ZLB_MYSQL_H
#include "mysql.h"
#include
#include
#include
using namespace std;
namespace zlb_mysql{
/*
* 字段操作
*/
class Field
{
public :
/* 字段名称 */
vector m_name;
/* 字段类型 */
vector m_type;
public :
Field();
~Field();
/* 是否是数字 */
bool IsNum(int num);
/* 是否是数字 */
bool IsNum(string num);
/* 是否是日期 */
bool IsDate(int num);
/* 是否是日期 */
bool IsDate(string num);
/* 是否是字符 */
bool IsChar(int num);
/* 是否是字符 */
bool IsChar(string num);
/* 是否为二进制数据 */
bool IsBlob(int num);
/* 是否为二进制数据 */
bool IsBlob(string num);
/* 得到指定字段的序号 */
int GetField_NO(string field_name);
};
/*
* 1 单条记录
* 2 [int ]操作 [""]操作
*/
class Record
{
public:
/* 结果集 */
vector m_rs;
/* 字段信息 占用4字节的内存 当记录数很大是回产生性能问题 */
Field *m_field;
public :
Record(){};
Record(Field* m_f);
~Record();
void SetData(string value);
/* [""]操作 */
string operator[](string s);
string operator[](int num);
/* null值判断 */
bool IsNull(int num);
bool IsNull(string s);
/* 用 value
相关文档:
http://www.trendcaller.com/2009/05/hadoop-should-target-cllvm-not-java.html
Sunday, May 10, 2009
Hadoop should target C++/LLVM, not Java (because of watts)
< type="text/javascript">
digg_url="http://www.trendcaller.com/2009/05/hadoop-should-target-cllvm-not-java.html";
Over the years, ......
这两天学习C++学累了,看了很多的网站论坛,突然感觉迷茫了,c/c++到底能做什么呢?现在JAVA很热,也很好找工作,而且学起来还听说很容易入门。不用学计算机基础类的知识,可C/C++就不同了,只学编程还不行,还得学什么数据结构,算法,计算机原理,操作系统,汇编语言,编程用具等等,需要好多,感觉一 ......
查看数据库版本 select version(), current_date();
显示数据库用 show databases;
选择某个数据库用use db_1;
创建数据库用create db_1;
插入数据用insert into db_1 values(...);
显示当前选择的数据库用select database();
创建表用create table tb_1 (...);
显示所有表用show tables;
显示某个表的所有内 ......
所有的数学函数在一个出错的情况下返回NULL。
-
单目减。改变参数的符号。
mysql> select - 2;
注意,如果这个操作符与一个BIGINT使用,返回值是一个BIGINT!这意味着你应该避免在整数上使用-,那可能有值-2^63!
ABS(X)
返回X的绝对值。
mysql ......
现在在WEB 应用中使用分页技术越来越普遍了,其中利用数据库查询分页是一种效率比较高的方法,
下面列出了Oracle, DB2 及 MySQL 分页查询写法。
一:Oracle
select * from (select rownum,name from table where rownum <=endIndex )
where rownum > startIndex
二:DB2
DB2分页查询
SELECT * ......