/// <summary>テーブルがnullまたは空</summary> public static bool IsNullOrEmpty(SQLiteTable table) { return(table == null || table.Rows.Count <= 0); }
/// <summary>ステートメントを実行して結果行列を取得</summary> private SQLiteTable ExecuteQuery(Statement statement) { if (!this.IsOpen) { return(null); } var pointer = statement.Pointer; var dataTable = new SQLiteTable(); // 列の生成 int columnCount = sqlite3_column_count(pointer); for (int i = 0; i < columnCount; i++) { string columnName = Marshal.PtrToStringAnsi(sqlite3_column_name(pointer, i)); dataTable.AddColumn(columnName, SQLiteColumnType.SQLITE_UNKNOWN); } // 行の生成 object [] row = new object [columnCount]; while (sqlite3_step(pointer) == SQLiteResultCode.SQLITE_ROW) { for (int i = 0; i < columnCount; i++) { if (dataTable.Columns [i].Type == SQLiteColumnType.SQLITE_UNKNOWN || dataTable.Columns [i].Type == SQLiteColumnType.SQLITE_NULL) { dataTable.Columns [i].Type = sqlite3_column_type(pointer, i); } switch (dataTable.Columns [i].Type) { case SQLiteColumnType.SQLITE_INTEGER: row [i] = sqlite3_column_int(pointer, i); break; case SQLiteColumnType.SQLITE_TEXT: IntPtr text = sqlite3_column_text(pointer, i); row [i] = Marshal.PtrToStringAnsi(text); break; case SQLiteColumnType.SQLITE_FLOAT: row [i] = sqlite3_column_double(pointer, i); break; case SQLiteColumnType.SQLITE_BLOB: IntPtr blob = sqlite3_column_blob(pointer, i); int size = sqlite3_column_bytes(pointer, i); byte [] data = new byte [size]; Marshal.Copy(blob, data, 0, size); row [i] = data; break; case SQLiteColumnType.SQLITE_NULL: row [i] = null; break; default: row [i] = null; break; } } dataTable.AddRow(row); } return(dataTable); }