mysqliteリファレンス
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
Mysqliteクラス
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
-
Mysqliteの本体です。
関数によっては、専用に用意されたクラスMysqlite_resultに結果を出力します。
-
// exp.mysqliteの変数を用意
Mysqlite mysqlite;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
Mysqlite::
Mysqlite::(char *dbname)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
コンストラクタです。
dbnameを渡すと、生成時にMysqlite::openを行います。
この場合、戻り値を受け取ることができませんが、openの失敗時には、getLastStatusにて判定できます。
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
int Mysqlite::getLastStatus()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
最後のステータスをintにて受け取ります。
戻り値は、sqliteのステータス(SQLITE_OK他)です。
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
std::string Mysqlite::getLastError()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
最後のエラー内容をstd::stringにて受け取ります。
Mysqlite::getLastStatusや、各種関数のステータスの戻り値がSQLITE_OK以外の場合、
この関数を使用して、詳細なエラー内容を取得できます。
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
std::string Mysqlite::getLastCommand()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
最後のコマンドをstd::stringにて受け取ります。
-
Mysqlite::exec
Mysqlite::exec_format
Mysqlite::get_table
Mysqlite::get_format
以上の関数を実行した際に発行したクエリ―が格納されます。
(※format内容が展開されて表示されるため、デバッグ時に有用です)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
int Mysqlite::open(char *dbname)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
sqliteをオープンします。
dbnameにオープンしたいデータベース名(データベースファイル)を指定してください。
戻り値は、sqliteのステータスです。
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
int Mysqlite::close()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
sqliteをクローズします。
デストラクタにて、closeを発行していますが、
基本的には、openした際には、任意のタイミングで閉じてください。
戻り値は、sqliteのステータスです。
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
int Mysqlite::exec(const char *sql, int (*callback)(void*,int,char**,char**) = NULL, void *p = NULL)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
sqliteのコマンドを実行します。
int sqlite3_exec(const char *sql, int (*callback)(void*,int,char**,char**), void *p, char **errmsg)
に渡し、メモリ解放箇所を自動化しています。
errmsgは、Mysqlite::getLastErrorにて取得できます。
callback、pはデフォルトではNULLを入れているため、sqlのみで使用可能です。
戻り値は、sqliteのステータスです。
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
int Mysqlite::exec_format(const char * format, ...)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
sqliteのコマンドを実行します。
可変長引数にて渡します。
書式はprintf、sprintf等と同じもので記述できます。
結果取得が必要な場合はMysqlite::get_formatを実行ください。
戻り値は、sqliteのステータスです。
-
// exp.テーブルに値を加える Mysqlite mysqlite("test.db"); if (mysqlite.getLastStatus() == SQLITE_OK) { // テーブルに要素を追加 mysqlite.exec_format("INSERT INTO %s VALUES(%d, '%s')", table_name, id, name); if (mysqlite.getLastStatus() != SQLITE_OK) { // エラーの場合はエラーを表示 puts(mysqlite.getLastError().c_str()); } mysqlite.close(); }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
int Mysqlite::get_table(const char *aSql, char **pazResult, int *pnRow, int *pnColumn)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
sqliteのコマンドを実行します。
int sqlite3_get_table(const char *aSql, char **pazResult, int *pnRow, int* pnColumn, char **pzErrmsg)
に渡し、メモリ解放箇所を自動化しています。
errmsgは、Mysqlite::getLastErrorにて取得できます。
戻り値は、sqliteのステータスです。
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
int Mysqlite::get_format(Mysqlite_result * result, const char * format, ...)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
sqliteのコマンドを実行し、resultに実行結果を取得します。
可変長引数にて渡します。
書式はprintf、sprintf等と同じもので記述できます。
戻り値は、sqliteのステータスです。
-
// exp.結果を取得してカラムのnameをstdoutに出力 Mysqlite_result result; Mysqlite mysqlite("test.db"); if (mysqlite.getLastStatus() == SQLITE_OK) { if (mysqlite.exec_format(&result, "SELECT * FROM %s", table_name) == SQLITE_OK) { for (int i = 0; i < result.size_row(); i++) { // カラムのnameをputsにて出力 puts(result.get_column(i, "name").c_str()); } } mysqlite.close(); }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
int Mysqlite::begin()
int Mysqlite::commit()
int Mysqlite::rollback()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
トランザクション関連を関数にて実行します。
戻り値は、sqliteのステータスです。
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
bool Mysqlite:full_column_names(bool flag)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
デフォルトでは、コマンド実行時に1行目のrowで取得できるカラム名は「カラム名」のみになっています。
「テーブル名.カラム名」としたい場合には、この関数のflagにtrueを渡して実行します。
-
-
-
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
Mysqlite_resultクラス
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
-
Mysqlite::get_format使用時に、結果を受け取るために使用するクラスです。
Mysqliteにて内部使用する関数以外のものを記述します。
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
void Mysqlite_result::clear()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
格納されていた各種要素を除去します。
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
int Mysqlite_result::size_column()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
格納されたカラム数を返します。
戻り値は、カラム数(int)です。
-
// exp.カラム数をstdoutに表示 Mysqlite_result result; Mysqlite mysqlite("test.db"); if (mysqlite.getLastStatus() == SQLITE_OK) { if (mysqlite.exec_format(&result, "SELECT * FROM %s", table_name) == SQLITE_OK) { // *にて、すべてのカラムを取得した場合も正常なカラム数がわかる printf("カラムの数は%d個", result.size_column()); } mysqlite.close(); }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
int Mysqlite_result::size_row()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
格納された行数を返します。
この値で取得した分だけforで回せば、すべての結果のテーブルを取得できます。
戻り値は、行数(int)です。
-
// exp.全ての要素をstdoutに表示 Mysqlite_result result; Mysqlite mysqlite("test.db"); if (mysqlite.getLastStatus() == SQLITE_OK) { if (mysqlite.exec_format(&result, "SELECT * FROM %s", table_name) == SQLITE_OK) { // 要求したテーブル数 printf("結果は%d行", result.size_row()); for (int i = 0; i < result.size_row(); i++) { if (i) putc('\n', stdout); for (int j = 0; j < result.size_column(); j++) { // 要素出力 printf("%s,", get_column(i, j).c_str()); } } } mysqlite.close(); }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
std::string Mysqlite_result::get_column(int position_row, int position_column)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
対応する行と、カラム位置にある値をstd::stringにて取得します。
Mysqlite_result::size_row、Mysqlite_result::size_columnにて取得した以上の値を渡してはいけません。
戻り値は、結果の文字列(std::string)です。
-
// Mysqlite_result::size_rowをご覧ください。
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
std::string Mysqlite_result::get_column(int position_row, std::string name)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
対応する行と、カラム名をstd::stringにて取得します。
Mysqlite_result::size_rowにて取得した以上の値を渡してはいけません。
nameは、CREATE TABLEにて付けたカラム名です。
Mysqlite::full_column_names(true)を実行した際は、
nameに「テーブル名.カラム名」にて要求することも可能です。
戻り値は、結果の文字列(std::string)です。
-
// exp.テーブルの要素name,addressをstdoutに表示 Mysqlite_result result; Mysqlite mysqlite("test.db"); if (mysqlite.getLastStatus() == SQLITE_OK) { if (mysqlite.exec_format(&result, "SELECT name,address FROM %s", table_name) == SQLITE_OK) { for (int i = 0; i < result.size_row(); i++) { // カラムのnameをputsにて出力 printf("名前は%s,", result.get_column(i, "name").c_str()); printf("住所は%sだよ!\n", result.get_column(i, "address").c_str()); } } mysqlite.close(); }
-
-
-
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
Mysqlite_rowクラス
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
-
Mysqlite_resultクラス内にて、内部処理するためのクラスです。
ただし、これを利用することにより、結果のカラム名を取得することができます。
ここでは、カラム名を取得するための関数を記述します。
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
std::string Mysqlite_row::get_column(position)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
位置に格納された文字列を取得します。
戻り値は、文字列(std::string)です。
-
// exp.結果のカラム名をstdoutに表示 Mysqlite_result result; Mysqlite mysqlite("test.db"); if (mysqlite.getLastStatus() == SQLITE_OK) { if (mysqlite.exec_format(&result, "SELECT * FROM %s", table_name) == SQLITE_OK) { for (int i = 0; i < result.size_column(); i++) { // headerには、カラム名が格納されているので、カラム全てを表示 puts(result.header.get_column(i).c_str()); } } mysqlite.close(); }
-
-
-