Sub Service_Create
'This is the program entry point.
'This is a good place to load resources that are not specific to a single activity.
Provider.Initialize
ph.Initialize("ph")
'-----db init----------
'File.Delete(others.Folder, dbName) 'deleted old database for clean test
Try
DBUtils.CopyDBFromAssets(dbName)
SQL.Initialize(others.Folder, dbName, True) 'DB
'-------------------------------------------------------------------
If SQL.IsInitialized = False Then
SQL.Initialize(others.Folder, dbName, True) 'DB open to check the version
End If
Dim v As Int = DBUtils.GetDBVersion(SQL)
Dim NewVer As Int = 1 'update here
If v < NewVer Then
SQL.Close
File.Delete(others.Folder, dbName) 'deleted old database
SQL.Initialize(others.Folder, dbName, True)
v = DBUtils.GetDBVersion(SQL) 'set = 1
DBUtils.SetDBVersion(SQL, NewVer) 'set new version = NewVer
End If
'-------------------------------------------------------------------
If SQL.IsInitialized = False Then
SQL.Initialize(others.Folder, dbName, True)
End If
Catch
ToastMessageShow("Проблема с базой знаний, обновите или переустановите приложение", True)
DBUtils.CopyDBFromAssets(dbName)
End Try
'-----db init end----------
Dim ft As Map, L As List
If DBUtils.TableExists(SQL, "facts") = False Then
ft.Initialize
ft.Put("id", DBUtils.DB_INTEGER)
ft.Put("name", DBUtils.DB_TEXT) 'reserved: nothing, me
ft.Put("alias", DBUtils.DB_TEXT)
ft.Put("desc", DBUtils.DB_TEXT)
ft.Put("img", DBUtils.DB_BLOB)
DBUtils.CreateTable(SQL, "facts", ft, "id")
L.Initialize
ft.Initialize
ft.Put("name", "") 'reserved: nothing
ft.Put("desc", "")
ft.Put("img", Null)
L.Add(ft)
ft.Initialize
ft.Put("name", "я") 'reserved: me
ft.Put("desc", "Вы, сам пользователь приложения")
ft.Put("img", Null)
L.Add(ft)
DBUtils.InsertMaps(SQL, "facts", L)
End If
If DBUtils.TableExists(SQL, "actions") = False Then
ft.Initialize
ft.Put("id", DBUtils.DB_INTEGER)
ft.Put("name", DBUtils.DB_TEXT) 'reserved: is, has
ft.Put("desc", DBUtils.DB_TEXT)
ft.Put("img", DBUtils.DB_BLOB)
DBUtils.CreateTable(SQL, "actions", ft, "id")
L.Initialize
ft.Initialize
ft.Put("name", "есть") 'reserved: is
ft.Put("desc", "есть у кого-то, быть, являться")
ft.Put("img", Null)
L.Add(ft)
ft.Initialize
ft.Put("name", "иметь") 'reserved: has
ft.Put("desc", "Содержать, обладать")
ft.Put("img", Null)
L.Add(ft)
DBUtils.InsertMaps(SQL, "actions", L)
End If
If DBUtils.TableExists(SQL, "hows") = False Then
ft.Initialize
ft.Put("id", DBUtils.DB_INTEGER)
ft.Put("name", DBUtils.DB_TEXT) 'reserved: nothing
ft.Put("desc", DBUtils.DB_TEXT)
ft.Put("img", DBUtils.DB_BLOB)
DBUtils.CreateTable(SQL, "hows", ft, "id")
L.Initialize
ft.Initialize
ft.Put("name", "") 'reserved: nothing
ft.Put("desc", "")
ft.Put("img", Null)
L.Add(ft)
DBUtils.InsertMaps(SQL, "hows", L)
End If
If DBUtils.TableExists(SQL, "whens") = False Then
ft.Initialize
ft.Put("id", DBUtils.DB_INTEGER)
ft.Put("name", DBUtils.DB_TEXT) 'reserved: nothing
ft.Put("desc", DBUtils.DB_TEXT)
ft.Put("img", DBUtils.DB_BLOB)
DBUtils.CreateTable(SQL, "whens", ft, "id")
L.Initialize
ft.Initialize
ft.Put("name", "") 'reserved: nothing
ft.Put("desc", "")
ft.Put("img", Null)
L.Add(ft)
DBUtils.InsertMaps(SQL, "whens", L)
End If
ft.Initialize
ft.Put("id", DBUtils.DB_INTEGER)
ft.Put("who_fact_id", DBUtils.DB_INTEGER)
ft.Put("does_action_id", DBUtils.DB_INTEGER)
ft.Put("at_fact_id", DBUtils.DB_INTEGER)
ft.Put("what_fact_id", DBUtils.DB_INTEGER)
ft.Put("how_id", DBUtils.DB_INTEGER)
ft.Put("when_id", DBUtils.DB_INTEGER)
ft.Put("where_id", DBUtils.DB_INTEGER)
ft.Put("img", DBUtils.DB_BLOB)
ft.Put("desc", DBUtils.DB_TEXT)
DBUtils.CreateTable(SQL, "relations", ft, "id")