如何在 iPhone 的 monotouch 中创建 SQLite 数据库?

发布于 2025-01-06 15:28:06 字数 177 浏览 6 评论 0原文

我是 iPad 开发新手。我已经使用 Xcode 4 在 Objective C 中创建了两个或三个 iPad 应用程序。现在我想使用 C# 在 MonoDevelop 工具中创建 iPad 应用程序。

我想创建一个基本的数据库项目,为此我需要一个使用 SQLite 数据库的基本教程。我在谷歌上搜索过,但没有找到任何教程。

I am new to iPad development. I have created two or three iPad applications in Objective C using Xcode 4. Now I want to create iPad applications in MonoDevelop tool using C#.

I want to create a basic database project, for that I need a basic tutorial, which uses a SQLite database. I searched on Google, but I didn't got any tutorial.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

隐诗 2025-01-13 15:28:06

我已经尝试过 SqLiteClient 和 SqLite-net。我建议您阅读此处的教程:
sqlite-net

对于我来说,我只需将 Sqlite.cs 文件放入我的项目中,然后用它来编译。

然后,使用您选择的工具创建一个 SQLite 数据库并将其添加到您的 MonoTouch 项目中,并确保将构建标志设置为“内容”。一旦您的项目中包含 SQLite 数据库(将文件放在您喜欢的任何位置),您就可以以只读方式访问它...除非您执行类似于以下示例中的代码的操作...它将文件重新定位到用户的个人文件夹,您的应用程序(和您的用户)将对其具有写入权限。

如果您需要用户在运行时对数据库执行 CRUD 操作,则需要在代码中包含类似以下内容以将文件复制到用户的个人文件夹:

using System.Linq;
using SQLite;

string personalFolder = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
string dbName = "myDatabase.db";
string dbPath = Path.Combine ( personalFolder, dbName);

// in this example I will always delete and re-copy the db to the users personal folder...
// modify to suit your needs...
if (File.Exists (dbPath) {
    File.Delete(dbPath);
}
File.Copy (dbName, dbPath);
// note: myDatabase.db for this example is in the root project folder.

using (var db = new SQLiteConnection(dbPath)) {
    // query using Linq...
}

希望有帮助。

I have tried both SqLiteClient and SqLite-net. I would recommend you read the tutorial here:
sqlite-net

For me, I just drop the Sqlite.cs file into my project and compile with it.

Then, using a tool of your choice, create a SQLite database and add it to your MonoTouch project being sure to set the build flag as "content". Once you have the SQLite database in your project (put the file anywhere you like), you can access it in a read-only fashion...unless you do something similar to the code in the example below...which relocates the file to the user's personal folder for which your app (and your user) will have write privileges to.

If you need the user, at run time, to do CRUD operations against the database, you will need to include in your code something like this to copy the file to the user's personal folder:

using System.Linq;
using SQLite;

string personalFolder = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
string dbName = "myDatabase.db";
string dbPath = Path.Combine ( personalFolder, dbName);

// in this example I will always delete and re-copy the db to the users personal folder...
// modify to suit your needs...
if (File.Exists (dbPath) {
    File.Delete(dbPath);
}
File.Copy (dbName, dbPath);
// note: myDatabase.db for this example is in the root project folder.

using (var db = new SQLiteConnection(dbPath)) {
    // query using Linq...
}

Hope that helps.

尬尬 2025-01-13 15:28:06

要访问 sqlite,您有很多选择,例如

  1. http://code.google.com/p/sqlite-net/< /a> 非常有用,也是我首选的方法
  2. System.Data 和 Mono.Data.SQLite http://docs.xamarin.com/ios/advanced_topics/system.data
  3. Mono 的 EntityFramework http://www.taimila.com/entify/index.php(不知道是否还在开发中)
  4. Vici Cool Storage 这是一篇不错的博客文章关于它 http://blog.activa.be /index.php/2010/02/vici-coolstorage-orm-on-monotouch-made-simple/ 和 Vici 的页面 http://viciproject.com/wiki/projects/coolstorage/home

以及许多其他内容,甚至 Apple 的 CoreData 也看到了(http://viciproject.com/wiki/projects/coolstorage/home)(http://viciproject.com/wiki/projects/coolstorage/home) /www.sgmunn.com/?p=1)但我想上述任何选项都更容易。

希望这有助于您入门

To access sqlite you have plenty of options, like

  1. http://code.google.com/p/sqlite-net/ very useful and my prefered method
  2. System.Data and Mono.Data.SQLite http://docs.xamarin.com/ios/advanced_topics/system.data
  3. EntityFramework for Mono http://www.taimila.com/entify/index.php (don't know if it is still in development)
  4. Vici Cool Storage Here is a nice blog post about it http://blog.activa.be/index.php/2010/02/vici-coolstorage-orm-on-monotouch-made-simple/ and Vici's page http://viciproject.com/wiki/projects/coolstorage/home

and many others even Apple's CoreData see (http://www.sgmunn.com/?p=1) but i guess any of the above options is easier that that.

hope this helps to get you started

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文