Recent Posts

Pages: 1 ... 7 8 [9] 10
81
Databases / Re: Help with writing, opening, reading and updating SQlite database
« Last post by Malkom on November 12, 2012, 04:47:18 PM »
that raises a question in my mind ... is it possible to test an application (run it inside HAC) in windows with a sq lite database file as local file (just like normal flatfiles)? or do i need to use another approach? like the http://localhost/ (xampp server) for example

I tried some apps for editing Android databases but some of them produced an incompatible database file - not sure if it was the SQLite structure or some file formating problem.

You could place your database file in the Game Book's Local folder on your desktop machine and work on it - then when you build the project it will be included in the built apk file.
82
Databases / Re: Help with writing, opening, reading and updating SQlite database
« Last post by Malkom on November 12, 2012, 04:43:03 PM »
Hi Jeroen

I'm sorry for the delay in getting back to you.

There is a bug with HAC regarding creating an internal  database although creating a local databse works fine.

I'll track the internal problem down and try to see what went wrong as it was definitely working when we tested it for v1.15 - perhaps when I was optimising the DB code I introduced a bug.


This is the code i use in the Startup section - note i commented out the internal database path setting

Code: [Select]
Global dbName,dbPath

@ filename
Put 'info.db' into dbName

@ --- form source path ---
Put LocalPathFN into dbPath
@Put DatabasePathFN into dbPath
Append '/' onto dbPath
Append dbname onto dbPath


Local exists,error
Local version,table,structure,dbid

@ --- try to open - if fails then create it ---
Put DbExistsFN(dbPath) into exists
If exists=1 then
    Put 'DB exists' into field 1
    Put DbOpenFN(dbPath,1) into error
    if error=1 then
        Put 'Could not open DB' after field 1
        Put dbPath after field 1
    endif
else
    Put 'DB does not exist' into field 1
    Put 1 into version
    Put 'books' into table

    Put '(' into structure
    Append '_id integer primary key autoincrement,' onto structure
    Append  ' title text not null,' onto structure
    Append  ' author text not null,' onto structure
    Append  ' comment text not null);' onto structure

    @ --- Create ---
    Put DbCreateFN(dbPath,version,table,structure) into dbid
    if dbid=0 then
        Put 'Could nopt create DB' after field 1
        Put dbPath after field 1
    endif
endif


I hope this helps.

Malkom

83
Databases / Re: Help with writing, opening, reading and updating SQlite database
« Last post by Malkom on November 12, 2012, 10:08:26 AM »
Hi Jeroen

I'm having a look at this now, should have something today.

Malkom
84
Databases / Re: Help with writing, opening, reading and updating SQlite database
« Last post by kaboekieman on November 09, 2012, 09:19:41 PM »
that raises a question in my mind ... is it possible to test an application (run it inside HAC) in windows with a sq lite database file as local file (just like normal flatfiles)? or do i need to use another approach? like the http://localhost/ (xampp server) for example 
85
Databases / Re: Help with writing, opening, reading and updating SQlite database
« Last post by kaboekieman on November 09, 2012, 08:17:24 PM »
woeps, just thought of something... I used to test the sql files I made a couple of months ago with localhost and phpmyadmin combo... How could I forget  ::) hmmms gonna test that first ;)
86
Databases / Re: Help with writing, opening, reading and updating SQlite database
« Last post by kaboekieman on November 09, 2012, 07:55:10 PM »
Hi Malkom thx for this extensive answer... but the code didn't save :( I have made a 'Local' map in the root of the app (in Windows) then copy/paste this code in the main code (at the start up section) ... just to see if a file was made, but no "info.db" file was made... if I echo the output (use message dbid) I saw the output was 0 and no file (table) was created...

Did I do something wrong?

Code: [Select]
Local dbname,path,exists,error
Local version,table,structure,dbid

@ filename
Put 'info.db' into dbname

@ --- form source path ---
Put DatabasePathFN into path
Append '/' onto path
Append dbname onto path

Put 1 into version
Put 'books' into table

Put '(' into structure
    Append '_id integer primary key autoincrement,' onto structure
    Append  ' title text not null,' onto structure
    Append  ' author text not null,' onto structure
    Append  ' comment text not null);' onto structure

@ --- Create ---
Put DbCreateFN(path,version,table,structure) into dbid

message dbid

grts, Jeroen
87
Databases / Re: Help with writing, opening, reading and updating SQlite database
« Last post by Malkom on November 09, 2012, 12:14:18 PM »
another question is could you use a 3rd party 'software' to edit the database file created with hac? For example phpliteadmin (https://code.google.com/p/phpliteadmin/)

Yes you should be able to as HAC just uses the Android OS to create and modify databases.

On an Android device i have used aSQLiteManager to open and verify if the database created was okay.
Its available on Google Market.
88
Databases / Re: Help with writing, opening, reading and updating SQlite database
« Last post by Malkom on November 09, 2012, 12:10:43 PM »
Hi Malkom... could you help me out with the basic beginning steps of writing a sq-lite database file?
I have experience in php/mysql... so the concept is clear, but implementation or even making a simple sq-lite db file prooved too difficult for me :( sorry... thought I was smarter hihi ;)

I looked at the recent help file (v1.16) and looked at the "8 how to" (blog) but could you help me with these steps?

1a. If the HAC application starts it has to look if the database file exists, if so, open it... if not create it (after which it will be open)... I guess I should setup this code into the script and then the main code of HAC (at the StartUp location)?

1b. Create database file in root of app, create table (creating tables with rows, primary key, auto increment I know). I saw the example database project but it didn't save ... so it was a little puzzeling how this works.

2. read database file and extract information via statements... I know how this is accomplished via MySQL queries and/or PHP statements (for example if then functions) but is there a list of statements or queries I can use in HAC in combination with SQlite??? During my php exam writing good mysql queries was one of the most difficult parts of the education, is this also true for SQlite? I know if you manage to write good queries you have a very powerfull tool at your side. 


My first goal will be to insert text from a table-cell into the app for every page and to implement a save location feature that will 'look' at the hac page the user last visited. After the user ends and starting the app up again it would automatically go to this location (save state). I already made this with a flatfile but this should also be possible with SQlite I guess.   

Well that's about it. Sorry that I have so many requests and questions. I do appriciate all your help

With kind regards, Jeroen

Hi Jeroen

I'm glad you are making progress and thanks for explaining your problems clearly.

Yes, the Startup section of MainCode is a good place to initialise or open the database.

By the way, I don't think Android will allow a file to be created in the root of the app - I had problems attempting this and had to use the database folder inside the app. For my own Android apps I nearly always use the local folder that a HAC app makes on the SDcard as some versions of Android had problems handling files inside the app folder.

The code below checks to see if the database file exists and either opens it or creates it

Code: [Select]
Local dbname,path,exists,error
Local version,table,structure,dbid

@ filename
Put 'info.db' into dbname

@ --- form source path ---
Put DatabasePathFN into path
Append '/' onto path
Append dbname onto path

@ --- try to open - if fails then create it --- 
Put DbExistsFN(path) into exists
If exists=1 then
   Put DbOpenFn(path,1) into error
   if error=1 then
      Message 'Could not open DB'
   endif
else
   Put 1 into version
   Put 'books' into table

   Put '(' into structure
   Append '_id integer primary key autoincrement,' onto structure
   Append  ' title text not null,' onto structure
   Append  ' author text not null,' onto structure
   Append  ' comment text not null);' onto structure

   @ --- Create ---
   Put DbCreateFN(path,version,table,structure) into dbid
   if dbid=0 then
      Message 'Could nopt create DB'
   endif
endif



I'm not sure if you have the debugger open while you work? - the DDMS - its available form the Go menu and when running shows lots of things happening inside the device including if a database fails to open etc.




Yes queries can be difficult. I work with PHP/MySQL most nights and still can't remember some queries and syntax. Therefore I either use a file I previously made on the website or use Google to search. Stackoverflow is a great site  for detail and sites like RoseIndia are a good place to start

http://www.roseindia.net/mysql/


Queries in HAC are very similar to those in SQL/PHP except that HAC queries might need extra single quotes or a character 39 in places.

There are 2 parts to using queries - making the query and then using any results return from the query

This query search for titles having Android in them:
Code: [Select]
Put 'SELECT _id, title FROM books WHERE title LIKE ' into query
Append ChrFN(39) onto query
Append '%Android%' onto query
Append ChrFN(39) onto query

Put query into field 3

Put DbExecQueryFN(path,query) into field 1


This uses the results from the query and iterates over every result:-

Code: [Select]
Put DbQueryCountFN(path) into count

Put count into field 4

Clear field 5
if count>0 then
    for n=1 to count
        Put DbQueryResultFN(path,n,'title') after field 5
    endfor
endif



I hope this makes things clearer

Malkom

89
Databases / Re: Help with writing, opening, reading and updating SQlite database
« Last post by kaboekieman on November 08, 2012, 07:43:28 PM »
another question is could you use a 3rd party 'software' to edit the database file created with hac? For example phpliteadmin (https://code.google.com/p/phpliteadmin/)
90
Databases / Help with writing, opening, reading and updating SQlite database
« Last post by kaboekieman on November 08, 2012, 03:42:23 PM »
Hi Malkom... could you help me out with the basic beginning steps of writing a sq-lite database file?
I have experience in php/mysql... so the concept is clear, but implementation or even making a simple sq-lite db file prooved too difficult for me :( sorry... thought I was smarter hihi ;)

I looked at the recent help file (v1.16) and looked at the "8 how to" (blog) but could you help me with these steps?

1a. If the HAC application starts it has to look if the database file exists, if so, open it... if not create it (after which it will be open)... I guess I should setup this code into the script and then the main code of HAC (at the StartUp location)?

1b. Create database file in root of app, create table (creating tables with rows, primary key, auto increment I know). I saw the example database project but it didn't save ... so it was a little puzzeling how this works.

2. read database file and extract information via statements... I know how this is accomplished via MySQL queries and/or PHP statements (for example if then functions) but is there a list of statements or queries I can use in HAC in combination with SQlite??? During my php exam writing good mysql queries was one of the most difficult parts of the education, is this also true for SQlite? I know if you manage to write good queries you have a very powerfull tool at your side. 


My first goal will be to insert text from a table-cell into the app for every page and to implement a save location feature that will 'look' at the hac page the user last visited. After the user ends and starting the app up again it would automatically go to this location (save state). I already made this with a flatfile but this should also be possible with SQlite I guess.   

Well that's about it. Sorry that I have so many requests and questions. I do appriciate all your help

With kind regards, Jeroen
Pages: 1 ... 7 8 [9] 10
anything