【发布时间】:2012-03-07 16:41:12
【问题描述】:
我在 SQLITE 和 View 中有两个表,我尝试合并这两个表(我的想法是从 table1 中获取所有行,其中 table1.field1 和 table2.field99 具有相同的值。
Tables and View are Table1,Table2 and View1
View code is "SELECT * FROM Table1 JOIN Table2 ON UPPER(Field1) LIKE UPPER(Table2.Field99)"
如果我跑了
SELECT * FROM View1;
如果我跑了
SELECT * FROM Table1 JOIN Table2 ON UPPER(Field1) LIKE UPPER(Field99);
从 sqlite shell 它返回行就好了。
但如果我尝试使用此代码在 C++ 中运行这些 SQL 语句:
if(sqlite3_prepare_v2(database,SQLStr,-1,&stmt,0)==SQLITE_OK){
int cols = sqlite3_column_count(stmt);
printf("Query OK: %s \nColumns: %i\n", SQLStr, cols);
while(1) {
status = sqlite3_step(stmt);
if(status == SQLITE_ROW) {
printf("This is a row!\n");
} else if(status == SQLITE_DONE) {
printf("Rows handled!\n");
break;
} else {
printf("Other status!\n");
break;
}
}
}
它只是返回:
Rows handled: SELECT * FROM View1;
Columns: 7
Rows handled!
但它不会像 shell 那样返回任何行。 (应该为查询中的每一行打印“这是一行!”。我尝试将表名添加到查询中但没有帮助。我还尝试运行例如 SELECT * FROM Table1; 然后 C++ 返回行。是不是让C++中的SQLITE不能处理JOINS或者Views?
【问题讨论】: