-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSample.cpp
More file actions
38 lines (31 loc) · 1.26 KB
/
Sample.cpp
File metadata and controls
38 lines (31 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "MySQLAgent.h"
#include <stdio.h>
using namespace std;
void main()
{
try
{
// 使用数据信息构造连接对象指针
CMySQLAgent* pMySQLAgent = new CMySQLAgent(m_strServerIP,m_strDBAccount,m_strDBPassword,m_strDBName,m_nDBPort);
// 支持类似printf函数格式不定参数输入,并将结果返回到结果集对象Result中
CMyResult Result = pMySQLAgent->Query("select orgname,coding from organization order by coding where deviceid = %s",m_strDevID);
int nIndex = 0;
do
{
// 支持以列名直接获取数据结,并根据变量类型自动返回相应数据
string strOgrname = Result["orgname"];
string strCoding = Result["coding"];
} while (++Result); // 目前结果集CMyResult类仅支持前置自增操作,即类型++Result
// CMyResult对象可以直接赋值新的结值,原结果集将被释放
Result = pMySQLAgent->Query("SELECT max(`deviceid`) AS maxDevid FROM devices;");
string strMaxID = Result["maxDevid"];
}
catch (CMySQLException& e)
{// 当连接数据异常,访问字段名不存在时,将会抛出异常,e.what_返回具体异常描述信息
string strException = e.what_;
}
catch(std::exception &e)
{
const char *szError = e.what();
}
}