简体   繁体   English

iOS SQLite与Android SQLite等效

[英]iOS SQLite equivalences with Android SQLite

I am a new programmer in Objective-C. 我是Objective-C的新程序员。 I have created an Android app and I've integrated SQLite. 我创建了一个Android应用程序,并且我已经集成了SQLite。 I want to build the same app in iOS. 我想在iOS中构建相同的应用程序。 In Android for SQLite manipulation I've created a class that extends from Content Provider: 在Android for SQLite操作中,我创建了一个从Content Provider扩展的类:

public class MyCProvider extends ContentProvider {
...
...
}

I've also overrided this methods: the boolean onCreate() method: 我也覆盖了这个方法:boolean onCreate()方法:

@Override
    public boolean onCreate() {
        dbHelper = new MySQLiteOpenHelper(getContext(), MySQLiteOpenHelper.DATABASE_NAME, null, MySQLiteOpenHelper.DATABASE_VERSION);
        return dbHelper != null;
    }



@Override
    public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
...
}



 @Override
        public String getType(Uri uri) {
...
}

@Override
    public Uri insert(Uri uri, ContentValues values) {
        SQLiteDatabase db = dbHelper.getWritableDatabase();

        String nullColumnHack = null;

        long id = -1;
        Uri contentURI = null;

        switch (uriMatcher.match(uri)) {
            case GROUP_ALL_ROWS:
                contentURI = GROUP_CONTENT_URI;
                id = db.insert(USEFUL_NUMBER_GROUP_TABLE_NAME, nullColumnHack, values);
                break;
...
...
}

I wanted to know this methods equivalences in Objective- C. Any idea about this? 我想在Objective-C中知道这种方法的等价性。对此有何想法?

SQLite is provided directly with iOS and you'd just use its native C API . SQLite直接与iOS一起提供,您只需使用其原生C API Apple doesn't provide any sort of wrapping. Apple不提供任何包装。

The attitude seems to be that you can use SQLite directly or you can use Core Data, which is really quite a different thing — it's a queriable object graph which implicitly relies on an opaque storage method that can be a SQLite-based relational database if you like but Core Data is explicitly not a relational database. 态度似乎是你可以直接使用SQLite,或者你可以使用Core Data,这是一个非常不同的东西 - 它是一个可查询的对象图,隐含地依赖于一个不透明的存储方法,如果你是一个基于SQLite的关系数据库但是Core Data显然不是关系数据库。 You can and should optimise for the SQL store underneath if that's the storage you pick but the database itself has a private schema and is not queried directly. 您可以并且应该优化下面的SQL存储,如果这是您选择的存储,但数据库本身具有私有模式,并且不直接查询。

As such there's no equivalent to SQLiteOpenHelper . 因此,没有与SQLiteOpenHelper等效的SQLiteOpenHelper If you want to use SQLite then you need to do the work of opening, creating, migrating, etc for yourself. 如果你想使用SQLite,那么你需要为自己做开放,创建,迁移等工作。

iOS also doesn't have an equivalent to ContentProvider because that's a formalised model structure to allow sharing of data between applications but iOS doesn't really do sharing of data between applications in that sense. iOS也没有ContentProvider的等价物,因为这是一个允许在应用程序之间共享数据的形式化模型结构,但iOS在这个意义上并不真正在应用程序之间共享数据。 Applications from the same developer can share disk storage, all applications can open each other by URL schema, etc, but you can't write code that different applications can all interact with. 来自同一开发人员的应用程序可以共享磁盘存储,所有应用程序可以通过URL架构等相互打开,但是您无法编写不同应用程序可以与之交互的代码。 So you'd just build whatever sort of model object you think most appropriate and its lifetime and interface would be whatever you explicitly decide. 因此,您只需构建您认为最合适的任何类型的模型对象,其生命周期和界面将是您明确决定的任何内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM