当你需要在纯C语言的应用程序中访问 MySQL 表中的数据时,是非常繁琐的事情,而该框架可以帮你大量的简化编码的工作,该框架采用 Python 开发,适用于 C 语言程序。

示例代码
#include <db.h>
#include <stdio.h>
#include <string.h>
#include <time.h>


int main (int argc, char **argv)
{
int ret;
MYSQL global_mysql;
MYSQL *m;

db_ex_customer *cust1;
db_ex_item *item1, *item2;

mysql_init (& global_mysql);

/*
* connect to MySQL as usual
*/
m = mysql_real_connect (& global_mysql, "localhost", "root", "", "ex1", 3036, NULL, 0);

/*
* pass the MySQL connection to function, that initializes the "ORM"
*/
ret = db_init (& global_mysql);

/*
* the *__new method creates empty structure
*/
cust1 = db_ex_customer__new ();
/*
* setting the structure attribute with allocated string,
* it will be freed during call of *__free method
*/
cust1->name = strdup ("alesak");

/*
* this methods inserts the structure into according table.
* If it has serial field, its value is reflected into structure
*/
ret = db_ex_customer__insert (cust1);

item1 = db_ex_item__new ();
item1->customer_id = cust1->id;
item1->itemname = strdup ("simple orm");

ret = db_ex_item__insert (item1);

item2 = db_ex_item__new ();
item2->customer_id = cust1->id;
item2->itemname = strdup ("advanced orm");

ret = db_ex_item__insert (item2);

db_ex_customer__free (cust1);
db_ex_item__free (item1);
db_ex_item__free (item2);

return (0);

}


项目主页:http://www.open-open.com/lib/view/home/1357894440650

更多相关文章

  1. c语言把mysql数据库语句和变量封装为一个语句
  2. 数据库语言分类DDL,DCL,DML
  3. Atitit 数据库 标准库 &#160;sdk 函数库 编程语言 mysql oracle
  4. C语言中的管道命令问题
  5. Dart语言和Android:访问手机的相机
  6. 使用自动化测试框架selenium,批量的进行截图
  7. 将一个youtube iframe放在另一个具有关闭图标的框架上
  8. ABP(现代ASP.NET样板开发框架)系列之21、ABP展现层——Javascrip
  9. Ajax中DWR框架使用简单步骤

随机推荐

  1. Android系列之Android系列之如何成为Andr
  2. RN系列:RN使用Android原生控件或自定义组
  3. 个人开发者做一款Android(安卓)App,androi
  4. 关于android常用的按下高亮的展示
  5. Android 学习1----控件的学习
  6. Android的图形显示原理(GDI)一
  7. Android 事件分发机制源码
  8. Android(安卓)ColorMatrix类图像颜色处理
  9. [置顶] Android曙光集群发来的邀请函
  10. Android Service 服务详细讲解