没有合适的资源?快使用搜索试试~ 我知道了~
首页MySQL++ v3.1.0教程
MySQL++ v3.1.0教程
5星 · 超过95%的资源 需积分: 10 7 下载量 62 浏览量
更新于2023-03-03
评论
收藏 370KB PDF 举报
MySQL++ is a powerful C++ wrapper for MySQL’s C API. Its purpose is to make working with queries as easy as working with STL containers.
资源详情
资源评论
资源推荐
MySQL++ v3.1.0 User Manual
Kevin Atkinson
Sinisa Milivojevic
Monty Widenius
Warren Young
Copyright © 1998-2001, 2005-2010 Kevin Atkinson (original author)MySQL ABEducational Technology
Resources
June 03, 2010
Table of Contents
1. Introduction .................................................................................................................................... 3
1.1. A Brief History of MySQL++ .................................................................................................. 3
1.2. If You Have Questions... .......................................................................................................... 4
2. Overview ........................................................................................................................................ 5
2.1. The Connection Object ........................................................................................................... 5
2.2. The Query Object .................................................................................................................. 5
2.3. Result Sets ........................................................................................................................... 5
2.4. Exceptions ............................................................................................................................ 7
3. Tutorial .......................................................................................................................................... 8
3.1. Running the Examples ............................................................................................................ 8
3.2. A Simple Example ................................................................................................................. 9
3.3. A More Complicated Example ................................................................................................ 10
3.4. Exceptions .......................................................................................................................... 11
3.5. Quoting and Escaping ........................................................................................................... 12
3.6. C++ vs. SQL Data Types ....................................................................................................... 13
3.7. Handling SQL Nulls ............................................................................................................. 15
3.8. MySQL++’s Special String Types ........................................................................................... 16
3.9. Dealing with Binary Data ...................................................................................................... 17
3.10. Using Transactions ............................................................................................................. 21
3.11. Which Query Type to Use? ................................................................................................... 25
3.12. Conditional Result Row Handling .......................................................................................... 26
3.13. Executing Code for Each Row In a Result Set .......................................................................... 28
3.14. Connection Options ............................................................................................................ 30
3.15. Dealing with Connection Timeouts ........................................................................................ 33
3.16. Concurrent Queries on a Connection ...................................................................................... 34
3.17. Getting Field Meta-Information ............................................................................................. 35
4. Template Queries ............................................................................................................................ 37
4.1. Setting up Template Queries ................................................................................................... 38
4.2. Setting the Parameters at Execution Time ................................................................................. 38
4.3. Default Parameters ............................................................................................................... 39
4.4. Error Handling .................................................................................................................... 40
5. Specialized SQL Structures .............................................................................................................. 41
5.1. sql_create ........................................................................................................................... 41
5.2. SSQLS Comparison and Initialization ...................................................................................... 42
5.3. Retrieving data .................................................................................................................... 43
5.4. Adding data ........................................................................................................................ 45
1
5.5. Modifying data .................................................................................................................... 50
5.6. Storing SSQLSes in Associative Containers .............................................................................. 51
5.7. Changing the Table Name ...................................................................................................... 52
5.8. Using an SSQLS in Multiple Modules ...................................................................................... 53
5.9. Harnessing SSQLS Internals .................................................................................................. 54
5.10. Having Different Field Names in C++ and SQL ....................................................................... 56
5.11. Expanding SSQLS Macros ................................................................................................... 56
5.12. Customizing the SSQLS Mechanism ...................................................................................... 57
5.13. Deriving from an SSQLS ..................................................................................................... 57
5.14. SSQLS and BLOB Columns ................................................................................................. 59
5.15. SSQLS and Visual C++ 2003 ................................................................................................ 61
6. Using Unicode with MySQL++ ......................................................................................................... 62
6.1. A Short History of Unicode .................................................................................................... 62
6.2. Unicode on Unixy Systems .................................................................................................... 62
6.3. Unicode on Windows ............................................................................................................ 63
6.4. For More Information ........................................................................................................... 64
7. Using MySQL++ in a Multithreaded Program ...................................................................................... 65
7.1. Build Issues ........................................................................................................................ 65
7.2. Connection Management ....................................................................................................... 66
7.3. Helper Functions .................................................................................................................. 70
7.4. Sharing MySQL++ Data Structures ......................................................................................... 71
8. Configuring MySQL++ ................................................................................................................... 72
8.1. The Location of the MySQL Development Files ......................................................................... 72
8.2. The Maximum Number of Fields Allowed ................................................................................ 72
8.3. Buried MySQL C API Headers ............................................................................................... 73
8.4. Building MySQL++ on Systems Without Complete C99 Support .................................................. 73
9. Using MySQL++ in Your Own Project ................................................................................................ 74
9.1. Visual C++ .......................................................................................................................... 74
9.2. Unixy Platforms: Linux, *BSD, OS X, Cygwin, Solaris... ............................................................ 75
9.3. OS X ................................................................................................................................. 76
9.4. MinGW .............................................................................................................................. 76
9.5. Eclipse ............................................................................................................................... 78
10. Incompatible Library Changes ......................................................................................................... 79
10.1. API Changes ...................................................................................................................... 79
10.2. ABI Changes ..................................................................................................................... 88
11. Licensing .................................................................................................................................... 90
11.1. GNU Lesser General Public License ...................................................................................... 91
11.2. MySQL++ User Manual License ........................................................................................... 98
2
MySQL++ v3.1.0 User Manual
1. Introduction
MySQL++ is a powerful C++ wrapper for MySQL’s C API. Its purpose is to make working with queries as easy as
working with STL containers.
The latest version of MySQL++ can be found at the official web site.
Support for MySQL++ can be had on the mailing list. That page hosts the mailing list archives, and tells you how you
can subscribe.
1.1. A Brief History of MySQL++
MySQL++ was created in 1998 by Kevin Atkinson. It started out MySQL-specific, but there were early efforts to try
and make it database-independent, and call it SQL++. This is where the old library name “sqlplus” came from. This
is also why the old versions prefixed some class names with “Mysql” but not others: the others were supposed to be
the database-independent parts. All of Kevin’s releases had pre-1.0 version numbers.
Then in 1999, MySQL AB took over development of the library. In the beginning, Monty Widenius himself did some
of the work, but later gave it over to another MySQL employee, Sinisa Milivojevic. MySQL released versions 1.0 and
1.1, and then Kevin gave over maintenance to Sinisa officially with 1.2, and ceased to have any involvement with the
library’ s maintenance. Sinisa went on to maintain the library through 1.7.9, released in mid-2001. It seems to be during
this time that the dream of multiple-database compatibility died, for obvious reasons.
With version 1.7.9, MySQL++ went into a period of stasis, lasting over three years. (Perhaps it was the ennui and
retrenchment following the collapse of the bubble that caused them to lose interest.) During this time, Sinisa ran the
MySQL++ mailing list and supported its users, but made no new releases. Contributed patches were either ignored or
put up on the MySQL++ web site for users to try, without any official blessing.
The biggest barrier to using MySQL++ during this period is that the popular C++ compilers of 2001 weren’t all that
compatible with the C++ Standard. As a result, MySQL++ used many nonstandard constructs, to allow for compatibility
with older compilers. Each new compiler released in the following years increased compliance, either warning about
or rejecting code using pre-Standard constructs. In particular, GCC was emerging from the mess following the EGCS
fork during this time. The fork was healed officially in 1999, but there’s always a delay of a few years between the
release of a new GCC and widespread adoption. The post-EGCS versions of GCC were only beginning to become
popular by 2001, when development on MySQL++ halted. As a result, it became increasingly difficult to get MySQL++
to build cleanly as newer compilers came out. Since MySQL++ uses templates heavily, this affected end user programs
as well: MySQL++ code got included directly in your program, so any warnings or errors it caused became your
program’s problem.
As a result, most of the patches contributed to the MySQL++ project during this period were to fix up standards
compliance issues. Because no one was bothering to officially test and bless these patches, you ended up with the worst
aspects of a bazaar development model: complete freedom of development, but no guiding hand to select from the
good stuff and reject the rest. Many of the patches were mutually incompatible. Some would build upon other patches,
so you had to apply them in the proper sequence. Others did useful things, but didn’t give a fully functional copy of
MySQL++. Figuring out which patch(es) to use was an increasingly frustrating exercise as the years wore on, and
newer GCCs became popular.
In early August of 2004, Warren Young got fed up with this situation and took over. He released 1.7.10 later that
month, which did little more than make the code build with GCC 3.3 without warnings. Since then, with a little help
from his friends on the Net, MySQL++ has lost a lot of bugs, gained a lot of features, gained a few more bugs, lost
them again... MySQL++ is alive and healthy now.
3
MySQL++ v3.1.0 User Manual
1.2. If You Have Questions...
If you want to email someone to ask questions about this library, we greatly prefer that you send mail to the MySQL++
mailing list. The mailing list is archived, so if you have questions, do a search to see if the question has been asked
before.
You may find people’s individual email addresses in various files within the MySQL++ distribution. Please do not
send mail to them unless you are sending something that is inherently personal. Not all of the principal developers of
MySQL++ are still active in its development; those who have dropped out have no wish to be bugged about MySQL++.
Those of us still active in MySQL++ development monitor the mailing list, so you aren’ t getting any extra “coverage”
by sending messages to additional email addresses.
4
MySQL++ v3.1.0 User Manual
2. Overview
MySQL++ has a lot of complexity and power to cope with the variety of ways people use databases, but at bottom it
doesn’t work all that differently than other database access APIs. The usage pattern looks like this:
1. Open the connection
2. Form and execute the query
3. If successful, iterate through the result set
4. Else, deal with errors
Each of these steps corresponds to a MySQL++ class or class hierarchy. An overview of each follows.
2.1.The Connection Object
A Connection object manages the connection to the MySQL server. You need at least one of these objects to do
anything. Because the other MySQL++ objects your program will use often depend (at least indirectly) on the
Connection instance, the Connection object needs to live at least as long as all other MySQL++ objects in your
program.
MySQL supports many different types of data connection between the client and the server: TCP/IP, Unix domain
sockets, and Windows named pipes. The generic Connection class supports all of these, figuring out which one
you mean based on the parameters you pass to Connection::connect(). But if you know in advance that your
program only needs one particular connection type, there are subclasses with simpler interfaces. For example, there’s
TCPConnection if you know your program will always use a networked database server.
2.2.The Query Object
Most often, you create SQL queries using a Query object created by the Connection object.
Query acts as a standard C++ output stream, so you can write data to it like you would to std::cout or
std::ostringstream. This is the most C++ish way MySQL++ provides for building up a query string. The library
includes stream manipulators that are type-aware so it’s easy to build up syntactically-correct SQL.
Query also has a feature called Template Queries which work something like C’s printf() function: you set up a
fixed query string with tags inside that indicate where to insert the variable parts. If you have multiple queries that are
structurally similar, you simply set up one template query, and use that in the various locations of your program.
A third method for building queries is to use Query with SSQLS. This feature lets you create C++ structures that
mirror your database schemas. These in turn give Query the information it needs to build many common SQL queries
for you. It can INSERT, REPLACE and UPDATE rows in a table given the data in SSQLS form. It can also generate
SELECT * FROM SomeTable queries and store the results as an STL collection of SSQLSes.
2.3. Result Sets
The field data in a result set are stored in a special std::string-like class called String. This class has conversion
operators that let you automatically convert these objects to any of the basic C data types. Additionally, MySQL++
defines classes like DateTime, which you can initialize from a MySQL DATETIME string. These automatic conversions
are protected against bad conversions, and can either set a warning flag or throw an exception, depending on how you
set the library up.
5
MySQL++ v3.1.0 User Manual
剩余97页未读,继续阅读
upczap
- 粉丝: 13
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- 2023年中国辣条食品行业创新及消费需求洞察报告.pptx
- 2023年半导体行业20强品牌.pptx
- 2023年全球电力行业评论.pptx
- 2023年全球网络安全现状-劳动力资源和网络运营的全球发展新态势.pptx
- 毕业设计-基于单片机的液体密度检测系统设计.doc
- 家用清扫机器人设计.doc
- 基于VB+数据库SQL的教师信息管理系统设计与实现 计算机专业设计范文模板参考资料.pdf
- 官塘驿林场林防火(资源监管)“空天地人”四位一体监测系统方案.doc
- 基于专利语义表征的技术预见方法及其应用.docx
- 浅谈电子商务的现状及发展趋势学习总结.doc
- 基于单片机的智能仓库温湿度控制系统 (2).pdf
- 基于SSM框架知识产权管理系统 (2).pdf
- 9年终工作总结新年计划PPT模板.pptx
- Hytera海能达CH04L01 说明书.pdf
- 数据中心运维操作标准及流程.pdf
- 报告模板 -成本分析与报告培训之三.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论1