Poco資料庫操作

2021-09-25 13:51:52 字數 1211 閱讀 3582

記錄集(recordset)

poco::data::recordset類提供了乙個通用的方法與資料庫的表進行互動,你可以使用recordset進行:

a. 遍歷資料表中所有的行與列

b. 獲取各列的元資訊,比如名稱,型別,長度等.

使用recordset,需要先建立乙個statement並執行他,從statement建立乙個recordset,如下:

statement select(session);

select << 「select * from person」;

select.execute();

recordset rs(select);

可以使用statement的limit限定來控制recordset的行數。

下面的例子演示如何遍歷recordset的每行每列:

bool more = rs.movefirst();

while (more)

std::cout << std::endl;

more = rs.movenext();

}tuples

在資料庫中的列型別已知的情閱下,poco::tuple以及tuple陣列提供了更簡便的方法獲取資料。因為它們的tylehandlers非常容易獲取。看看如下**:

typedef poco::tupleperson;

typedef std::vector people;

people people;

people.push_back(person(「bart simpson」, 「springfield」, 12));

people.push_back(person(「lisa simpson」, 「springfield」, 10));

statement insert(session);

insert << 「insert into person values(:name, :address, :age)」,

use(people), now;

當然,tuple也可以用於查詢:

statement select(session);

select << 「select name, address, age from person」, into(people), now;

for (people::const_iterator it = people.begin(); it != people.end(); ++it)

Poco資料庫操作

1.poco進行資料庫操作的步驟一般是 a.建立會話 session b.從db中讀寫資料 into,use c.使用statements d.使用容器 collection 資料,集合.e.使用limit限定 f.如何使用複雜的資料型別 如何將乙個c 物件對映到資料庫的表 下面是乙個簡單的運算元據...

POCO中資料庫的操作

poco關於資料庫封裝操作放在data目錄下,以前用過關於sqlite的封裝庫感覺挻不錯的,這次要寫個c s的軟體資料庫採用的是sql server,於是就再次選用了poco。關於odbc的操作示例在poco中好像執行時沒有啥效果,今天看著示例自已寫了個。第一步 將資料庫tacksjk.mdf附加到...

Poco資料庫操作使用者手冊 二

記錄集 recordset poco data recordset類提供了乙個通用的方法與資料庫的表進行互動,你可以使用recordset進行 a.遍歷資料表中所有的行與列 b.獲取各列的元資訊,比如名稱,型別,長度等.使用recordset,需要先建立乙個statement並執行他,從statem...