Simple MySQL-C ORM 介绍
当你需要在纯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); }
Simple MySQL-C ORM 官网
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。