Creating a database for mobile journal? - Solved

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

DR White
Posts: 686
Joined: Fri Aug 23, 2013 12:29 pm
Location: Virginia, USA

Creating a database for mobile journal? - Solved

Post by DR White » Wed May 26, 2021 6:34 pm

I have never written a database type app before. I want to write a simple mobile journal.
Each entry consist of 9 elements - DataEntry[tDate,tEvent,tSubEvent,tLocation,tSubLocation,tActionTaken,tComment,tExtra1,tExtra2].

How do I make a database "Record" that will be stored in a file on a phone?

Would anybody be interested to point me in the best direction so that the user can search the data entries based on any of the 9 elements.

I was thinking that there was some kind of special encoding used to save arrays?

What is the best way to search for a data entry based on matches of the 9 array elements?

Thanks,

David
Last edited by DR White on Thu May 27, 2021 4:30 pm, edited 1 time in total.

DR White
Posts: 686
Joined: Fri Aug 23, 2013 12:29 pm
Location: Virginia, USA

Re: Creating a database for mobile journal?

Post by DR White » Thu May 27, 2021 12:40 pm

I believe that a data grid will work for my application.

simon.schvartzman
Posts: 641
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

Re: Creating a database for mobile journal?

Post by simon.schvartzman » Thu May 27, 2021 1:13 pm

DR White, have you seen the lesson below regarding working with DBs?

Should be a good starting point

https://lessons.livecode.com/m/4069/l/5 ... e-database
Simon
________________________________________
To ";" or not to ";" that is the question

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Creating a database for mobile journal?

Post by dunbarx » Thu May 27, 2021 1:41 pm

Hi.

Not that there is any reason not to use an array, but is there any compelling reason to?

Searching a dataSet, whether an array or simple delimited data, is straightforward. My real question is this, are you concerned with the mechanics of an actual database, or really just talking about searching through data?

Craig

DR White
Posts: 686
Joined: Fri Aug 23, 2013 12:29 pm
Location: Virginia, USA

Re: Creating a database for mobile journal?

Post by DR White » Thu May 27, 2021 2:24 pm

Craig,

It will be a Searchable Troubleshooting Journal.

It will be a tool for electrical technicians to build a knowledge base on the phone for problems they encounter.

I just started yesterday and I thought I would try to use "Best Practice", before I hack a way of doing it (the way I usually do things).

I attached what I think the data entry page might look like.

Thanks for responding,

David
Attachments
Searchable Troubleshooting Journal.livecode.zip
(2.79 KiB) Downloaded 112 times

Mikey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 755
Joined: Fri Jun 27, 2008 9:00 pm

Re: Creating a database for mobile journal?

Post by Mikey » Thu May 27, 2021 2:43 pm

I tend to think of everything as a DB, and I tend to use db's no matter what, but I have a feeling that for someone who has not implemented one, before, it might be overkill for you for your first mobile app, especially since DB's (generally) require learning SQL and some of the vagaries around parallel data structures (tables).
You absolutely can do it, and if this is intended as a learning exercise for yourself, by all means, jump in, but understand that there is going to be double the learning overhead for this first one, even before you get into the finer points.

DR White
Posts: 686
Joined: Fri Aug 23, 2013 12:29 pm
Location: Virginia, USA

Re: Creating a database for mobile journal?

Post by DR White » Thu May 27, 2021 2:52 pm

Since in most cases the number of entries (records) will be less than a 1000, maybe I can use a simpler array file. Any guidance will be appreciated.

Thanks

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Creating a database for mobile journal?

Post by bogs » Thu May 27, 2021 3:15 pm

Well, I don't know enough about mobile to say this would work there, but, if I were doing this on a desktop with a 1000 or so records, I'd just use cards themselves. 'Find' works pretty good for the simple task limits you set forth.
Image

Mikey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 755
Joined: Fri Jun 27, 2008 9:00 pm

Re: Creating a database for mobile journal?

Post by Mikey » Thu May 27, 2021 3:18 pm

Searches on mobes and on SSD's on desktops are so fast that I'm not sure your dataset size will matter.
Maybe the first thing you should do is make a test worst-case container, with, say, 5000 lines in it, delimited by commas or tabs, or whatever you choose.
Try searching the container for something, e.g. "A/C"
Basically the goal of this test is to write your search algorithm in classic LC code.
Is it fast enough? Does it do everything you want?
If the answer to either of those is "no", then maybe a DB is appropriate, and we move on to learning about databases.
If the answer is "yes", then maybe using a flat file or the HC approach with just a bunch of cards will be good enough.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7228
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Creating a database for mobile journal?

Post by jacque » Thu May 27, 2021 4:20 pm

If you want to use an array, you can store it on disk with arrayEncode. To read it back into usable format, use arrayDecode. Searching an array requires looping through all the elements but it's very fast.

A plain text file would also work and you could use any of the offset commands to search, which would also be very fast.

I agree that using a database for the first time would be a steeper learning curve.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

DR White
Posts: 686
Joined: Fri Aug 23, 2013 12:29 pm
Location: Virginia, USA

Re: Creating a database for mobile journal?

Post by DR White » Thu May 27, 2021 4:29 pm

Jacque,

I have used arrayEncode before (I think you suggested it on a previous app) and it worked well. I think it is a good suggestion for this app as well.
I just wanted to be sure that I wasn't overlooking a better method.

Thanks for everyone's help,

David :D

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Creating a database for mobile journal? - Solved

Post by dunbarx » Thu May 27, 2021 7:03 pm

The suggestion to use 1000 cards is sound in theory, but know that LC starts to slow noticeably after about 3000 cards.

I have stored similar data, and loaded in as needed onto a single card. The user cannot tell the difference, even if you want to include special effects every time you update.

Craig

Mikey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 755
Joined: Fri Jun 27, 2008 9:00 pm

Re: Creating a database for mobile journal? - Solved

Post by Mikey » Thu May 27, 2021 7:11 pm

Good tip.
There are so many ways to skin this cat in LC.

mrcoollion
Posts: 720
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Creating a database for mobile journal? - Solved

Post by mrcoollion » Fri May 28, 2021 9:11 am

Take a look at post viewtopic.php?f=12&t=33338
Here is a stack that enables you to save data in an array and retrieve it including encryption.

Regards,

Paul

kdjanz
Posts: 300
Joined: Fri Dec 09, 2011 12:12 pm
Location: Fort Saskatchewan, AB Canada

Re: Creating a database for mobile journal? - Solved

Post by kdjanz » Sun May 30, 2021 5:02 am

DemoSaveAppData.livecode.zip
(2.76 KiB) Downloaded 126 times
With all credit to mrcoollion, I have modified his stack to make it a little more modern.
All the fields now use a behaviour script for their functions, so all the code for all the fields is in a single spot for modifications. This also means that if you clone a field by dragging it with the option/alt key, it keeps the behaviour settings, so that field is saved automatically as well without having to script it or set it manually.

I also changed the save function to only save to the documents folder. When I tried running his stack from my downloads folder, no data was saved because the stack did not have permissions to write to that folder. All apps can write to the documents folder however, so this is a safer place to save data on desktop or mobile.

I changed the original Encrypt and Decrypt commands to be functions that returned the data to the caller. I just thought the code looked cleaner with function calls instead of commands with multiple inputs and outputs.

The guts and logic are still his, so credit still goes to him - although I'm stealing it for a ToDo app that I am working on now. I'm going to try to make it a script only library stack to add to my existing work. Never done that before, so learning is guaranteed to occur! 8-)

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”