回答編集履歴
1
SELECTの例を追記しました
test
CHANGED
@@ -49,3 +49,79 @@
|
|
49
49
|
sqliteのDBをあらかじめ作っておきたい場合は、[PupSQLite](https://www.eonet.ne.jp/~pup/) などのフリーソフトでsqliteのDBファイルを作る事が出来ます。
|
50
50
|
|
51
51
|
作ったDBファイル(*.db)をResources以下に配置しておけば良いと思います。
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
---
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
### 追記
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
Resources/test.db の内容をSELECTする例を記載します。
|
64
|
+
|
65
|
+
```cpp
|
66
|
+
|
67
|
+
void MainScene::test() {
|
68
|
+
|
69
|
+
sqlite3* db = nullptr;
|
70
|
+
|
71
|
+
if (sqlite3_open("test.db", &db) != SQLITE_OK) {
|
72
|
+
|
73
|
+
return;
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
// sampleテーブルの全レコードを抽出
|
80
|
+
|
81
|
+
std::string sql = "SELECT * FROM sample";
|
82
|
+
|
83
|
+
sqlite3_stmt *stmt = nullptr;
|
84
|
+
|
85
|
+
int result = sqlite3_prepare_v2(db, sql.c_str(), 128, &stmt, nullptr);
|
86
|
+
|
87
|
+
if (result != SQLITE_OK) {
|
88
|
+
|
89
|
+
sqlite3_reset(stmt);
|
90
|
+
|
91
|
+
sqlite3_finalize(stmt);
|
92
|
+
|
93
|
+
sqlite3_close(db);
|
94
|
+
|
95
|
+
return;
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
int colCount = sqlite3_column_count(stmt);
|
102
|
+
|
103
|
+
while (sqlite3_step(stmt) == SQLITE_ROW) {
|
104
|
+
|
105
|
+
for (int col = 0; col < colCount; col++) {
|
106
|
+
|
107
|
+
std::string name = sqlite3_column_name(stmt, col);
|
108
|
+
|
109
|
+
std::string value = StringUtils::format("%s", sqlite3_column_text(stmt, col));
|
110
|
+
|
111
|
+
CCLOG("name=%s, value=%s", name.c_str(), value.c_str());
|
112
|
+
|
113
|
+
}
|
114
|
+
|
115
|
+
}
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
sqlite3_reset(stmt);
|
120
|
+
|
121
|
+
sqlite3_finalize(stmt);
|
122
|
+
|
123
|
+
sqlite3_close(db);
|
124
|
+
|
125
|
+
}
|
126
|
+
|
127
|
+
```
|