litehelpers / Cordova-SQLitePlugin-legacy-iOS-broken-bug666

Cordova/PhoneGap SQLitePlugin for iOS as of September 2013, no longer supported - BROKEN due to BUG litehelpers/Cordova-sqlite-storage#666
89 stars 30 forks source link

Android 2.3.3 #29

Closed beauohara closed 11 years ago

beauohara commented 11 years ago

First off Thanks for this plugin. Working great on everything but Android 2.3.3

When I set the target in eclipse to 2.3.3 I get errors around this code and the method getType():

// for old Android SDK remove lines from HERE:
                        if(android.os.Build.VERSION.SDK_INT >= 11)
                        {
                            switch(cur.getType (i))
                            {
                                case Cursor.FIELD_TYPE_NULL:
                                    row.put(key, null);
                                    break;
                                case Cursor.FIELD_TYPE_INTEGER:
                                    row.put(key, cur.getInt(i));
                                    break;
                                case Cursor.FIELD_TYPE_FLOAT:
                                    row.put(key, cur.getFloat(i));
                                    break;
                                case Cursor.FIELD_TYPE_STRING:
                                    row.put(key, cur.getString(i));
                                    break;
                                case Cursor.FIELD_TYPE_BLOB:
                                    row.put(key, cur.getBlob(i));
                                    break;
                            }
                        }
                        else // to HERE.
                        {
                            row.put(key, cur.getString(i));
                        }

It seems there is a comment about how to work around, but I am not exactly sure what to do. Should I save everything using row.put(key, cur.getString(i));

beauohara commented 11 years ago

It seems happy when I comment this out and just use

row.put(key, cur.getString(i));

But I want to be sure I am not making an error. Did sqlite cursor on Android before 11 not understand field types?

csperle commented 11 years ago

Did sqlite cursor on Android before 11 not understand field types? Yes. See: http://developer.android.com/reference/android/database/Cursor.html#getType(int) -> Since API Level 11 (Android 3.0)

I too, would like to use the plugin for Android 2.3. Is this possible?

beauohara commented 11 years ago

I can't get it to work on 2.3.3. 3.1 and 4 seem to work ok in the simulator.

philiprjarnold commented 11 years ago

I'm going to try to implement this myself, but maybe with a "hack" to get around the problem in 2.3.3 and below

the problem is that in Android 10 and below is that each field is just a field, with no differentiation on the actual data type, and 11 introduced getType()

I have a feeling that for 2.2 & 2.3.3 you should just put them back as getString rather than trying to work out the data type, especially since JavaScript it pretty much type-less, and you can run things like isNaN(), etc

EDIT: the big hint that it was introduced in SDK 11 is this line: if(android.os.Build.VERSION.SDK_INT >= 11) the problem is that the code won't compile on pre-11 with that code in place!!!!

brodybits commented 11 years ago

Sorry for the delay. Considering that JSON and Javascript is not strongly-typed as pointed out by @philiprjarnold, I would say remove everything marked "for old Android SDK" [< SDK 11] if you have any problems. Please report if there is anything else still wrong specifically for version 2.3.3.

brodybits commented 11 years ago

Closing this issue. If there are any build errors please remove everything marked "for old Android SDK" [< SDK 11].