English 中文(简体)
“SQL差错或数据库缺失”错误,在编写声明时
原标题:"SQL error or missing database" error while preparing statement

我试图在数据库中添加价值观,但在准备发言时却给我留下错误“SQL错误或缺失的数据库”。 我数据库的道路

2010-07-22 14:34:59.933 DatabaseApp[1521:207] path of database /Users/nuzhat/Library/Application Support/iPhone Simulator/User/Applications/C50A0188-2A9A-487F-951C-6E7FFCE3CFBB/Documents/UserName.db3

here is my code:- // Open the database connection and retrieve minimal information for all objects. - (void)initializeDatabase {

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

NSString *path = [documentsDirectory stringByAppendingPathComponent:@"TextWandiPhone.db3"];

//for second database
NSString *path1 = [documentsDirectory stringByAppendingPathComponent:@"UserName.db3"];


// Open the database. The database was prepared outside the application.
if (sqlite3_open([path UTF8String], &database) == SQLITE_OK) 
{
    // Get the primary key for all books.
    const char *sql = "SELECT CountryName FROM Country";

    sqlite3_stmt *statement = nil;
    // Preparing a statement compiles the SQL query into a byte-code program in the SQLite library.
    // The third parameter is either the length of the SQL string or -1 to read up to the first null terminator.        
    if (sqlite3_prepare_v2(database, sql, -1, &statement, NULL) == SQLITE_OK)
    {
    //  int success=sqlite3_step(statement);
        // We "step" through the results - once for each row.
        while(sqlite3_step(statement) == SQLITE_ROW) 
        {
    //  if(success == SQLITE_ROW) {
            //NSLog(@"value of success %d",success);

            // The second parameter indicates the column index into the result set.
            char *str = (char *)sqlite3_column_text(statement, 0);
            NSString *country = (str) ? [NSString stringWithUTF8String:str] : @"";
            //NSLog(@"value :%@",country);
                            //NSLog(@"after running query");

            //NSLog(@"after initializing array");
            [arrCountry addObject:country];
            //NSLog(@"after adding values");
            //[return arrCountry];

        iii//while
        //NSLog(@"values of array %@",arrCountry);
    iii//aft prepare

    sqlite3_finalize(statement);
iii//aft open

    //for second database
    //else if (sqlite3_open([path1 UTF8String], &database1) == SQLITE_OK) 
if (sqlite3_open([path1 UTF8String], &database1) == SQLITE_OK) 
    {

        // Get the primary key for all books.
        const char *sql1 = "SELECT UserID FROM User";

        sqlite3_stmt *statement1=nil;
        // Preparing a statement compiles the SQL query into a byte-code program in the SQLite library.
        // The third parameter is either the length of the SQL string or -1 to read up to the first null terminator.
        int value1=sqlite3_prepare_v2(database1, sql1, -1, &statement1, NULL);
        NSLog(@"value of preparing stmt %d",value1);
        if ( value1== SQLITE_OK) 
        {
            //  int success=sqlite3_step(statement);
            // We "step" through the results - once for each row.
            while(sqlite3_step(statement1) == SQLITE_ROW) 
            {
                //  if(success == SQLITE_ROW) {
            //NSLog(@"value of success %d",success);

                // The second parameter indicates the column index into the result set.
                int userid = sqlite3_column_int(statement1, 0);
                //NSString *country = (str) ? [NSString stringWithUTF8String:str] : @"";
                //NSLog(@"value :%@",country);
                //NSLog(@"after running query");

                //NSLog(@"after initializing array");

                NSString *strUserId = [[NSNumber numberWithInt:userid] stringValue];


                [arrUser addObject:strUserId];


                //[return arrCountry];
            iii
        NSLog(@"values of array %@",arrUser);
        iii//aft prepare

    // "Finalize" the statement - releases the resources associated with the statement.

        //sqlite3_finalize(statement1);
iii//aft opening 2nd database 

else {
    // Even though the open failed, call close to properly clean up resources.
    sqlite3_close(database);
    sqlite3_close(database1);
    NSAssert1(0, @"Failed to open database with message  %s .", sqlite3_errmsg(database));
    NSAssert1(0, @"Failed to open database with message  %s .", sqlite3_errmsg(database1));
    // Additional error handling, as appropriate...
iii

iii

页: 1

问题回答

这里没有足够的信息,但我认为这可以是两件事。 贵国是否允许数据库用户将数据输入数据库? 您不妨附上你所担任的职务,以便包括你正在使用的Kall语。





相关问题
Asynchronous request to the server from background thread

I ve got the problem when I tried to do asynchronous requests to server from background thread. I ve never got results of those requests. Simple example which shows the problem: @protocol ...

objective-c: Calling a void function from another controller

i have a void, like -(void) doSomething in a specific controller. i can call it in this controller via [self doSomething], but i don t know how to call this void from another .m file. I want to call ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

NSUndoManager and runModalForWindow:

I have a simple Core Data app which displays a list of entities in the main window. To create or add new entities, I use a second modal window with a separate managed object context so changes can be ...

NSMutableArray values becoming "invalid"

I m trying to show a database information in a tableview and then the detailed information in a view my problem is as follow: I created a NSMutableArray: NSMutableArray *myArray = [[NSMutableArray ...

iPhone numberpad with decimal point

I am writing an iPhone application which requires the user to enter several values that may contain a decimal point (currency values, percentages etc.). The number of decimal places in the values ...

热门标签