Skip to main content

Add an SQLite database to an iPhone app



I am trying to learn SQLite, and I am building an iPhone app. But I would like to add an SQLite database to my building app. I have got three tutorials, but I am not clear on that code.





How can I add an SQLite database to my building app? What would sample code look like?



Source: Tips4all

Comments

  1. First of all you need to create your database.
    From the command line create your db file.

    sqlite3 mydb.db


    Then create the tables within your database

    CREATE TABLE tags (id int(5), name varchar(255), created_at datetime, updated_at datetime);


    Repeat that for any tables that you want in your database.

    Then you need to include the database file in your project. Add the existing database file to your project as you would any other existing file.

    Next you will have to link in the framework to interact with the database. This can be found under you current iPhone SDK folder.

    /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.2.sdk/usr/lib/libsqlite3.0.dylib

    Finally you have to include the header file sqlite3.h from

    /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.2.sdk/usr/include/sqlite3.h

    It should now be possible to write code to access your sqlite database from within your iPhone application.

    ReplyDelete
  2. There is lots of information on the web.

    Have you looked at the demo application? SQLite Book List This shows examples of common database functions under SQLite. This is effectively using the standard SQLite C APIs.

    There are Objective C wrappers which may suite you more.
    EntropyDB, SQLitePersistenceObjects and FMDB.

    I found this Tutorial and this list of resources which may help.

    Recently I've been using an ORM SQLite.net It is the way to go for me but then I'm developing in MonoTouch C#.

    Tony

    ReplyDelete
  3. I'd also recommend looking at FMDB. It makes using SQLite slightly more Objective-C/Cocoa-like. It's not a full ORM wrapper or anything though; it just wraps the C API into something a bit more flavoursome.

    ReplyDelete
  4. http://sqlite.org/docs.html is a good place to start.

    You might get more useful help if you are more specific about what you are trying to do, and what obstacles you are encountering.

    ReplyDelete
  5. CoreData should help, but I can't find it anywhere in the list of importable Frameworks.

    You could take a peek at the iPhone examples, especially the SQLite Book List example.

    ReplyDelete
  6. If you use Firefox, there's this handy addon that you can use to manage and create an SQLite database.

    ReplyDelete

Post a Comment

Popular posts from this blog

[韓日関係] 首相含む大幅な内閣改造の可能性…早ければ来月10日ごろ=韓国

div not scrolling properly with slimScroll plugin

I am using the slimScroll plugin for jQuery by Piotr Rochala Which is a great plugin for nice scrollbars on most browsers but I am stuck because I am using it for a chat box and whenever the user appends new text to the boxit does scroll using the .scrollTop() method however the plugin's scrollbar doesnt scroll with it and when the user wants to look though the chat history it will start scrolling from near the top. I have made a quick demo of my situation http://jsfiddle.net/DY9CT/2/ Does anyone know how to solve this problem?

Why does this javascript based printing cause Safari to refresh the page?

The page I am working on has a javascript function executed to print parts of the page. For some reason, printing in Safari, causes the window to somehow update. I say somehow, because it does not really refresh as in reload the page, but rather it starts the "rendering" of the page from start, i.e. scroll to top, flash animations start from 0, and so forth. The effect is reproduced by this fiddle: http://jsfiddle.net/fYmnB/ Clicking the print button and finishing or cancelling a print in Safari causes the screen to "go white" for a sec, which in my real website manifests itself as something "like" a reload. While running print button with, let's say, Firefox, just opens and closes the print dialogue without affecting the fiddle page in any way. Is there something with my way of calling the browsers print method that causes this, or how can it be explained - and preferably, avoided? P.S.: On my real site the same occurs with Chrome. In the ex