winston 发表于 2008-11-30 10:32:35

转 SQL C++代码自动生成器(sql2class)介绍

来自:http://blog.csdn.net/chenxiaohong3905/archive/2008/11/11/3278950.aspx
         Newzai的专栏

sql2class 是一个工具,用于把数据库表格转换为一个C++对象。配合odbcwrapped 和mysqlwrapped 2个面向对象的数据库接口封装库一起使用。

odbcwrapped用C++类封装了Windows OBDC API的调用。
mysqlwrapped用C++类封装了 Mysql C API的调用。

2个库都使用统一的接口。简化了程序员在开发数据库相关应用时操作数据库的API的掌握。实现着那些ADO,DAO,OBDC等一大堆windows上的数据库操作API以及MYSQL 提供的C API和其它数据库提供的众多的API而大脑发热时,要学习一大堆重复的相同的知识时,郁闷不, warpped和sql2class是你的救星。

他们至少可以让你的整个开发过程节省1/3的时间。

warpped 主要类介绍:
Database 类:严格的来说应该是一个数据库的连接池对象。管理这客户端到数据库服务器之间的TCP连接器。
Query 类:用于执行SQL查询语句,包括SELECT,UPDATE,DELETE等。所有SQL标准支持的数据库语句。
Query需要一个Datadase对象,每次执行SQL操作时,会从Database对象所管理的连接池中请求得到一个数据库连接对象,并执行相关的数据库操作。而后释放连接(并不断开,而是返回Database对象所管理的连接池中,下次复用)。


sql2calss基于warpped生成数据库表格对象,进一步封装了数据库的API,让程序员面对的是每一个数据库表格所表示的对象,而不是那些枯草无畏的数据库操作语句的C API。有时需要掌握一些简单的SQL语句。在多表查询、操作时还是需要使用到warpped提供的类,此时sql2class生成的类无能为力或者效率低下。

适合范围:
         用于Windows开发居于ODBC驱动的数据库,比如MYSQL,MSSQL。ACCES----只要支持 ODBC驱动的都可以使用。
         MYSQL C API 如果在linux时,没有OBDC等驱动程序,目前只支持mysql
       sqlite 一个文件数据库,类型与微软的ACCESS。
源码以及更加详细的参考信息:http://www.alhem.net/project/sql2class/index.html

winston 发表于 2008-11-30 10:33:12

SQL C++ code generator

Welcome to the SQL C++ code generator (sql2class) homepage.
The sql2class utility is a code generation tool, able to convert output from the mysql tool mysqldump to simple C++ classes. From version 1.7 it also supports the sqlite database (version 3).
For each database table, one C++ class will be generated containing member variables for each column as well as methods to read / insert / update / delete records and also return the record as XML. The primary key and unique indexes of a table is used to generate specific constructors for each table, to spawn single objects.
Generated classes use any of the *wrapped database libraries to access the database - no code generated by sql2class is actually dependent on any specific database server.
Check out the *wrapped/sql2class tutorial here.
The source code of this tool is made available under the GPL license.
Download latest version

[*]sql2class-1.9.3.tar.gz 2008-06-25[*]sql2class-1.9.3.zip 2008-06-25Changes
2008-06-25: Fix crash bug when a table does not have a primary key.
2006-04-10: Classes are now generated with get/set methods for field data. To get the old behaviour a '-getset' option has been added that disables generation of get/set methods. Name mangling of table and column names can be turned off with the new option '-mangle'. The parser will now be able to correctly read files with both unix and win32 end of line markers.
2006-03-28: Mysql set and enum support working again. Added header comment block to each file, containing the exact command line and sql2class version used to generate the file. Added option to suppress GPL license in generated files. Win32 project file added (vs6). Limited experimental java support added.
2005-09-14: Some sql parsing issues fixed.
2005-08-12: Added sqlitewrapped library support (-sqlite command line argument), and modified parser to support sqlite quirks.
2005-04-12: Using unique index to generate update / erase methods if primary index is not available. If no primary / unique index is available, then update / erase methods for that table is not generated.
2005-02-22: Modified generated classes so they easily can be used together with sql join statements. Added support to parse newer output format from mysqldump.
2004-08-20: Small changes because of name change of the mysql wrapper. Include and header files have new name ("mysqlwrapped").
2004-08-17: Changed generated code to work with latest version of the mysql C API C++ wrapper.
2004-08-05: Bugfix in mediumtext handling. When using generated class to read from the database the last line in a mediumtext field was always lost.
2004-07-09: support for mediumtext in generated insert / update sql statements.
2004-06-22: Improved mysql column type support: unsigned integers, bigint, enum and set. Integer values are now stored in member variables of the correct bit size and sign. Enum and Set fields are handled by two classes, enum_t and set_t. The options "-stl" and "-global" are now by default ON.
2004-06-18: minor bugfixes to stay compatible with dbdesigner.
2004-05-30: Every index / key that returns one unique object are used to generate constructors. Removed the constructor that spawns an object from a "long" input parameter, and replaced that constructor with one constructor for the primary key and constructors for each unique key.
2004-05-21: New command line option '-stl' generates classes that use std::string instead of char * for text/string columns. Replaced a lot of char * input parameters with std::string.
Older versions
[*]sql2class-1.9.2.tar.gz 2006-09-26[*]sql2class-1.9.2.zip 2006-09-26[*]sql2class-1.9.1.tar.gz 2006-04-24[*]sql2class-1.9.1.zip 2006-04-24[*]sql2class-1.9.tar.gz 2006-04-10[*]sql2class-1.9.zip 2006-04-10[*]sql2class-1.8.1.tar.gz 2006-03-29[*]sql2class-1.8.1.zip 2006-03-29[*]sql2class-1.8.tar.gz 2006-03-28[*]sql2class-1.8.zip 2006-03-28[*]sql2class-1.7.1.tar.gz 2005-09-14[*]sql2class-1.7.tar.gz 2005-08-12[*]sql2class-1.6.tar.gz 2005-04-12[*]sql2class-1.5.tar.gz 2005-02-22[*]sql2class-1.4.tar.gz 2004-08-20[*]sql2class-1.3.3.tar.gz 2004-08-17[*]sql2class-1.3.2.tar.gz 2004-08-05[*]sql2class-1.3.1.tar.gz 2004-07-09[*]sql2class-1.3.tar.gz 2004-06-22[*]sql2class-1.2.1.tar.gz 2004-06-18[*]sql2class-1.2.tar.gz 2004-05-30[*]sql2class-1.1.tar.gz 2004-05-21[*]sql2class-1.0.tar.gzLinks[*]sql2class @ www.mysql.com[*]sql2class in FSF Directory[*]sql2class at Code Generation Network
页: [1]
查看完整版本: 转 SQL C++代码自动生成器(sql2class)介绍