1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| class wenSql(context: Context, name: String, factory: SQLiteDatabase.CursorFactory?, ver: Int) : SQLiteOpenHelper(context, name, factory, ver) { val Create_ = "Create table wen(id integer primary key autoincrement,title text , url text);" val mContext = context var marks = arrayListOf<Map<String, Any>>() override fun onCreate(db: SQLiteDatabase?) { try { db!!.execSQL(Create_) } catch (e: NullPointerException) { println(e) }
}
override fun onUpgrade(db: SQLiteDatabase?, oldVersion: Int, newVersion: Int) {}
fun wen_add(title: String, url: String, db: SQLiteDatabase,hand:Handler): Boolean { try { var cv = ContentValues() cv.put("title", title) cv.put("url", url) Log.d("添加:",cv.getAsString("title")) Log.d("添加:",cv.getAsString("url"))
db.insert("wen", null, cv) cv.clear() var msg = Message() msg.what = 2 hand.sendMessage(msg) return true } catch (e: NullPointerException) { var msg = Message() msg.what = 0 hand.sendMessage(msg) return false } } fun wen_delete(sql: String): Boolean { return false }
fun wen_query(id: String, db: SQLiteDatabase, hand: Handler): Boolean { var cursor = db.query("wen", null, null, null, null, null, null, null) if (cursor.moveToFirst()) { do { var temMAp = linkedMapOf<String, Any>() var title = cursor.getString(cursor.getColumnIndex("title")) var url = cursor.getString(cursor.getColumnIndex("url")) temMAp.put("title", title) temMAp.put("url", url) marks.add(temMAp) } while (cursor.moveToNext()) println(marks) val msg = Message() msg.what = 1 hand.sendMessage(msg) cursor.close() } return false }
fun wen_update(sql: String): Boolean { return false }
}
|