0

「X」という名前の新しいテーブル (既存の「Y」データベースから取得) を作成すると、メールに添付できません。私はそれが私のiPhoneにあることを知っています(私がそうしているように)

["SELECT * FROM sqlite_master where type='table'"]

最初)。前もって感謝します。これが私のコードです:

-(void)displayComposerSheet
{
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;

    //FileManager - Object allows easy access to the File System.
    NSFileManager *FileManager = [NSFileManager defaultManager];

    //Get the complete users document directory path.
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    //Get the fist path in the array.
    NSString *documentsDirectory = [paths objectAtIndex:0];

    //Create the complete path to the database file.
    NSString *databasePath = [documentsDirectory stringByAppendingPathComponent:@"X.sqlite"];

    NSData *data = [NSData dataWithContentsOfFile:databasePath];
    [picker addAttachmentData:data mimeType:@"application/x-sqlite3" fileName:@"X.sqlite"];

    [picker setMessageBody:emailBody isHTML:NO];
    [self presentViewController:picker animated:YES completion:nil];

}
4

1 に答える 1

0

基本的に、私は次のことを行いました。

    //Delete Output file if it exists
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK)
{
    if(insertStmt == nil)
    {
        sqlite3_stmt *selectStatement;
        const char *sqlStatement=[[NSString stringWithFormat:
                                   @"DROP TABLE IF EXISTS fileOutput"]UTF8String];
        if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK)
        {
            if (sqlite3_prepare_v2(database, sqlStatement, -1, &selectStatement, NULL) != SQLITE_OK)
            {
                NSAssert1(0, @"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(database));
            }
            while (sqlite3_step(selectStatement) == SQLITE_ROW)
            {

            }
            sqlite3_reset(selectStatement);
            sqlite3_finalize(selectStatement);
        }
    }
}
sqlite3_close(database);

//Add Output file
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK)
{
    if(insertStmt == nil)
    {
        sqlite3_stmt *selectStatement;
        const char *sqlStatement=[[NSString stringWithFormat:
                                   @"CREATE TABLE fileOutput AS SELECT * FROM Y WHERE 0"]UTF8String];
        if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK)
        {
            if (sqlite3_prepare_v2(database, sqlStatement, -1, &selectStatement, NULL) != SQLITE_OK)
            {
                NSAssert1(0, @"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(database));
            }
            while (sqlite3_step(selectStatement) == SQLITE_ROW)
            {

            }
            sqlite3_reset(selectStatement);
            sqlite3_finalize(selectStatement);
        }
    }
}
sqlite3_close(database);

//Copy into table
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK)
{
    if(insertStmt == nil)
    {
        sqlite3_stmt *selectStatement;
        const char *sqlStatement=[[NSString stringWithFormat:
                                   @"INSERT INTO fileOutput SELECT * FROM Y WHERE file IN ('%@')",pickerField]UTF8String];
        if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK)
        {
            if (sqlite3_prepare_v2(database, sqlStatement, -1, &selectStatement, NULL) != SQLITE_OK)
            {
                NSAssert1(0, @"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(database));
            }
            while (sqlite3_step(selectStatement) == SQLITE_ROW)
            {

            }
            sqlite3_reset(selectStatement);
            sqlite3_finalize(selectStatement);
        }
    }
}
sqlite3_close(database);

//Make the OUTPUT sqlite file
[self deleteEditableCopyOfDatabaseIfNeeded];

//ATTACH OUTPUT file to Y
const char *outputDBPath = [[documentsDirectory stringByAppendingPathComponent:@"X.sqlite"] UTF8String];

if (sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
    NSString *attach = [NSString stringWithFormat: @"ATTACH DATABASE \'%s\' AS X", outputDBPath];
    const char *attachSQL = [attach UTF8String];
    char *errorMessage;


    if (sqlite3_exec(database, attachSQL, NULL, NULL, &errorMessage) == SQLITE_OK) {

//Copy the table into sqlite file
            sqlite3_stmt *selectstmt;
            const char *sqlStatement1 = "INSERT OR REPLACE INTO X (all the fields go here ) SELECT * FROM fileOutput";
            if (sqlite3_prepare_v2(database,sqlStatement1, -1, &selectstmt, NULL) == SQLITE_OK) {
                while (sqlite3_step(selectstmt) == SQLITE_ROW) {
                //if(sqlite3_step(selectstmt)==SQLITE_DONE)
            //{
                    NSLog(@"insert successfully");
                }
            }
            else
            {
                NSLog(@"insert not successfully");

            }
            sqlite3_finalize(selectstmt);
        }
    }
    sqlite3_close(database);




[self sendEmailWithFile];
于 2013-02-28T23:04:48.043 に答える