目录
前言
一、数据表字段介绍
二、新增数据表
三、删除数据表
四、修改数据表
五、查询数据表
前言
上文已经介绍C/C++使用ProcessDB的基本操作,本文将针对数据表的相关操作进行介绍
一、数据表字段介绍
二、新增数据表
// ProcessDB_API_TEST.cpp : ProcessDB数据库示例//#include <iostream>#include <string>#include <stdio.h>#include <time.h>#include <conio.h>#include "processdb_v2.h"using namespace std;int main(int argc, char* argv[]){int res = 0;EBASE ebase = { 0 };/* 初始化连接控制块 */res = ebase2_init(&ebase);if (0 != res){cout << "ebase2_init failed !" << endl;getchar();exit(1);}/*设置超时时间*/int timeout = 30;ebase2_set_options(&ebase, EBASE_CONNECTION_TIMEOUT, &timeout);/* 建立连接 */res = ebase2_connect(&ebase, "127.0.0.1", 8301, "root", "root");if (0 != res){cout << "login failed, \n";getchar();exit(1);}/* 新增数据表 *///名称要按照数据库名+.+新建数据表名res = ebase2_add_table(&ebase, "D99.T99","Dsecription");if (res != 0){cout << "ebase2_add_table failed, error code:" << res << endl;getchar();exit(1);}else{cout << "ebase2_add_table sucess!!" << endl;}/* 关闭连接 */ebase2_close(&ebase);return 0;}
三、删除数据表
// ProcessDB_API_TEST.cpp : ProcessDB数据库示例//#include <iostream>#include <string>#include <stdio.h>#include <time.h>#include <conio.h>#include "processdb_v2.h"using namespace std;int main(int argc, char* argv[]){int res = 0;EBASE ebase = { 0 };/* 初始化连接控制块 */res = ebase2_init(&ebase);if (0 != res){cout << "ebase2_init failed !" << endl;getchar();exit(1);}/*设置超时时间*/int timeout = 30;ebase2_set_options(&ebase, EBASE_CONNECTION_TIMEOUT, &timeout);/* 建立连接 */res = ebase2_connect(&ebase, "127.0.0.1", 8301, "root", "root");if (0 != res){cout << "login failed, \n";getchar();exit(1);}/* 删除数据表 *///名称要按照数据库名+.+新建数据表名res = ebase2_delete_table(&ebase, "D99.T8");if (res != 0){cout << "ebase2_delete_table failed, error code:" << res << endl;getchar();exit(1);}else{cout << "ebase2_delete_table sucess!!" << endl;}/* 关闭连接 */ebase2_close(&ebase);return 0;}
四、修改数据表
// ProcessDB_API_TEST.cpp : ProcessDB数据库示例//#include <iostream>#include <string>#include <stdio.h>#include <time.h>#include <conio.h>#include "processdb_v2.h"using namespace std;int main(int argc, char* argv[]){int res = 0;EBASE ebase = { 0 };/* 初始化连接控制块 */res = ebase2_init(&ebase);if (0 != res){cout << "ebase2_init failed !" << endl;getchar();exit(1);}/*设置超时时间*/int timeout = 30;ebase2_set_options(&ebase, EBASE_CONNECTION_TIMEOUT, &timeout);/* 建立连接 */res = ebase2_connect(&ebase, "127.0.0.1", 8301, "root", "root");if (0 != res){cout << "login failed, \n";getchar();exit(1);}/* 修改数据表 *///名称要按照数据库名+.+新建数据表名res = ebase2_modify_table(&ebase, "D99.T99","New Description");if (res != 0){cout << "ebase2_modify_table failed, error code:" << res << endl;getchar();exit(1);}else{cout << "ebase2_modify_table sucess!!" << endl;}/* 关闭连接 */ebase2_close(&ebase);return 0;}
五、查询数据表
// ProcessDB_API_TEST.cpp : ProcessDB数据库示例//#include <iostream>#include <string>#include <stdio.h>#include <time.h>#include <conio.h>#include "processdb_v2.h"using namespace std;int main(int argc, char* argv[]){EBASE_RES result = NULL;int res = 0;EBASE ebase = { 0 };/* 初始化连接控制块 */res = ebase2_init(&ebase);if (0 != res){cout << "ebase2_init failed !" << endl;getchar();exit(1);}/*设置超时时间*/int timeout = 30;ebase2_set_options(&ebase, EBASE_CONNECTION_TIMEOUT, &timeout);/* 建立连接 */res = ebase2_connect(&ebase, "127.0.0.1", 8301, "root", "root");if (0 != res){cout << "login failed, \n";getchar();exit(1);}/* 根据库名+表名查询数据表 */res = ebase2_query_table(&ebase, "D99.T99", &result);if (res != 0){cout << "ebase2_query_table failed, error code:" << res << endl;getchar();exit(1);}else{//数据表查询成功cout << "ebase2_query_table sucess!!" << endl;char* desc = NULL;ebase2_get_table_desc(result, 0, &desc);cout << "table desc:" << desc << endl;OBJECT_ID id;ebase2_get_table_id(result, 0, &id);cout << "table id:" << id << endl;char* name = NULL;ebase2_get_table_name(result, 0, &name);cout << "table name:" << name << endl;}/* 关闭连接 */ebase2_close(&ebase);return 0;}
运行示例如下:
ebase2_query_table sucess!!table desc:New Descriptiontable id:10030002table name:T99