Hecl and SQLite on Android |
||||
Главная | Программные продукты | Freesource программные продукты | Статьи по Tcl/Tk | Статьи | Контакт | Карта сайта | |||
|
The Hecl Programming Language is a high-level scripting language implemented in Java, created by David N. Welton. This are sources using with hecl for gpsmta - GPS tracker / GPS monitoring for Android Sorry, I do not know java. This code for the specialist may seem strange :-) Hecl and SQLite on Android1. Create file hecl/android/src/org/hecl/android/DBHelper.java ----------------------------------------------------- package org.hecl.android; import android.content.Context; import android.app.Activity; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.os.Environment; public class DBHelper extends SQLiteOpenHelper{ //private static final String DATABASE_NAME = Environment.getExternalStorageDirectory().getPath() + "/gpsmta/gpsmta.db"; private static final String DATABASE_NAME = "gpsmta.db"; public DBHelper(Context context) { super(context, DATABASE_NAME, null, 15); } @Override public void onCreate(SQLiteDatabase database) { database.execSQL("CREATE TABLE log (id integer primary key, date text, name text);"); database.execSQL("CREATE TABLE coords (id integer primary key, seconds integer, data text, secondssend integer);"); database.execSQL("create index coords_seconds_secondssend on coords(seconds,secondssend);"); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL("DROP TABLE IF EXISTS coords"); onCreate(db); } } 2. Recompile Hecl
ant packageAndroidBuilder
3. Using with Hecl java org.hecl.android.DBHelper dbhelper set iddbs [dbOpen] proc dbOpen { } { set context [activity] set db [dbhelper -new $context] set dbw [$db getwritabledatabase] return $dbw } proc dbEval { h query } { $h execsql "$query" if { eq [lindex $query 0] "insert" } { set c [$h rawquery "select last_insert_rowid()" [null]] set st [$c movetofirst] set rowid [$c getstring 0] $c close return $rowid } } proc dbSelect { h query } { set lret "" set c [$h rawquery "$query" [null]] set st [$c movetofirst] if { > $st 0 } { for { set i 0 } { < $i [$c getcount] } { incr $i } { set lrow "" for { set j 0 } { < $j [$c getcolumncount] } { incr $j } { set s [$c getstring $j] lappend $lrow $s } lappend $lret $lrow $c movetonext } $c close } return $lret } # example select set lret [dbSelect $iddbs $query] if { ne $lret "" } { set issend 0 foreach { el } $lret { puts $el } } # example insert set id [dbEval $iddbs "insert into coords values(null,'$seconds','$data','[clock seconds]')"] # example delete dbEval $iddbs "delete from coords where id = $id" |
|||||||||
Copyright © Эдуард Зозуля | ||||||||||