virtual void CreateTable() { Statement stmt(*m_sqliteDriver, "SELECT count(*) FROM sqlite_master WHERE type = 'table' AND name = 'MyTable'"); if (stmt.executeStep()) { Column col = stmt.getColumn(0); int tableCount = col.getInt(); if (tableCount == 0) { m_sqliteDriver->execute("create table MyTable(id integer primary key autoincrement,name varchar(100))"); } } }
//test create TEST_F(SqliteWrapTest, CreateTable) { int result; Statement stmt(*m_sqliteDriver, "SELECT count(*) FROM sqlite_master WHERE type = 'table' AND name = 'MyTable'"); if (stmt.execute()) { Column col = stmt.getColumn(0); int tableCount = col.getInt(); if (tableCount == 0) { result = m_sqliteDriver->execute("create table MyTable(id integer primary key autoincrement,name varchar(100))"); EXPECT_EQ(result, SQLITE_OK); Statement stmt(*m_sqliteDriver, "select * from MyTable"); int column_count = stmt.getColumnCount(); EXPECT_EQ(column_count, 2); } } }