我正在使用以下代码
- (int)GetTextCount
{
NSMutableArray *audioArray=[[NSMutableArray alloc]init];
int count = 0;
//This method is defined to retrieve data from Database
NSString *dbPath=filePath;
sqlite3 *database;
if(sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) {
// Setup the SQL Statement and compile it for faster access
/*
SELECT (
SELECT COUNT(*)
FROM tab1
) AS count1,
(
SELECT COUNT(*)
FROM tab2
) AS count2
FROM dual
*/
const char *sqlStatement = "select count(*) from photo where mid=? ";
//const char *sqlStatement = "select * from textt where mid=?";
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
sqlite3_bind_int(compiledStatement, 1, memoryData.memoryId);
//(compiledStatement, 1, [header UTF8String], -1, SQLITE_TRANSIENT);
while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
AudioData *data=[[AudioData alloc]init];
//create the MemoryData object to store the data of one record
// Read the data from the result row
int pId=sqlite3_column_int(compiledStatement, 0);
NSLog(@"total audiosssss are %i",pId);
//NSString *filePath=[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];
//filePath=[self retrievePath:filePath];
//[data setAudioId:pId];
//[data setFilePath:filePath];
//Store every object of MemoryData in t
[audioArray addObject:data];
} // end of the while
}
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);
return [audioArray count];
}
我需要从四个表中计算行数,但是现在我正在运行单独的查询,这会降低性能,因此我想运行一个查询从四个表中选择,帮忙解决如何实现?