Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8397369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:46:15+00:00 2026-06-09T20:46:15+00:00

Possible Duplicate: Exporting Sqlite table data to csv file programatically – xcode iOS 5

  • 0

Possible Duplicate:
Exporting Sqlite table data to csv file programatically – xcode iOS 5 (for an ipad app)

I am developing a simple app. I am using sqlite to save data into a table (locally, in app documents folder). I want to problematically export this table data in a csv file and email it to a person. I mean I want to physically access the csv file after conversion in iPad…. Can anybody give an example application to download? Or the code?
Please help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T20:46:16+00:00Added an answer on June 9, 2026 at 8:46 pm

    This should give you a good idea. Assuming a table with 2 rows, this code reads all the values in the table and writes them to and NSString, which is then written to a CSV file in the documents directory. Let me know if you need clarification on how to make this code work with your specific project.

        NSString *csv = [[NSString alloc] init];
    
        sqlite3 *database;
    
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        NSString *sqLiteDb
        = [documentsDirectory stringByAppendingPathComponent:@"INSERT_DATABASE_NAME.sqlite3"];
    
    
        if(sqlite3_open([sqLiteDb UTF8String], &database) == SQLITE_OK) {
            const char *sqlStatement = [[NSString stringWithFormat:@"SELECT * FROM myTable"] UTF8String];
            sqlite3_stmt *compiledStatement;
            if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
    
               while(sqlite3_step(compiledStatement) == SQLITE_ROW) { 
                 //this assumes that there are two rows in your database you want to get data from   
                 [csv stringByAppendingFormat:@"%@,%@\n", [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 0)], [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)]];
               }
    
              sqlite3_finalize(compiledStatement);
              sqlite3_close(database);
            }else{
                NSLog(@"database error");
            }
        }
    
    NSError *error = nil;
    [csv writeToFile:[documentsDirectory stringByAppendingPathComponent:@"myFile.csv"]
          atomically:YES encoding:NSUTF8StringEncoding error:&error];
    
    [csv release];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Dealing with commas in a CSV file We are exporting a bulk
Possible Duplicate: In need of JavaScript Solution for Exporting table to Excel which works
Possible Duplicate: Ignore SVN files when exporting a WAR file from Eclipse? Using eclipse
Possible Duplicate: how to add a reference to the system.data.SQLite.dll to the windows phone
Possible Duplicate: Exporting an Environment Variable in Ruby I need to set several environment
Possible Duplicate: Extracting dollar amounts from existing sql data? I have a column in
Possible Duplicate: Transparent images with C# WinForms I am coding an app which will
I am developing a dimension table, the requiremnet is to insert all possible unique
Possible Duplicate: How do you send email from a Java app using Gmail? How
Possible Duplicate: Parsing XML String in C# How to process the below XML file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.