I’ve been working with Corona Labs on some app work. I had one of the projects working and then there was an update and it broke the app. As I’ve learned, and been told now by more than a few different sources, is that Corona is not a business development platform. Interestingly enough a couple years ago I was told by someone from the company that although they were going to add the business app development to Corona. Didn’t really happen.

But – what’s the difference? Not a heck of a lot. Most development environments could be used for business apps and I was having a hard time being convinced that it couldn’t be done in Corona. The idea of Corona is you write the code then compile and publish for iPhone, iPad, Android, Nook and Kindle. No major rewrites of the code. Sounded like a plan to me.

I have been certified in Titanium and I have to say that is probably the better environment for business apps. But I liked the idea of 4 platforms for the price of one, and I had gotten pretty far down the road with Corona so I decided to stick it out and get it to do a business app.

To me a business program involves inputting and outputting information to and from a database as it’s major workings vs a game type software that moves graphics around. So all I needed to do was figure out what tools Corona had that I could move data around with.

The easiest database available to use for Corona is Sqlite. Not a bad database at all. Getting up to speed with it was not much different than switching between MSSQL and MYSQL and Fox and __ fill in the blanks.

The basics of database manipulation can be summed up as CRUD – Create, Read, Update and Delete. If you can do that, your on your way. Corona and Sqlite could do this fairly well. The Corona docs left a bit to be desired – there was a bunch out there  – but they were not organized very well (I started this project almost two years ago – there have been changes for the better since then) – and it was incomplete. I would find docs try it, it wouldn’t work, then I find another page that would say “It used to work this way but it doesn’t anymore”. Arghhhh!!! That and the assumption that you knew certain things – a carnal knowledge of Corona.

The biggest problem I hit was passing the ID field of the chosen record to the next screen. Before the update mentioned above there was an easy way to list the rows on the screen and pass with each one the ID. NOT the id of the row – that’s always numbered 1,2,3,4… etc down the screen. The ID I needed came from the table. If you listed the data in the way it was created in the table it came out sequentially. But if you have various names to another field and sorted on that, then they weren’t sequential. Record 1 may come after record 5, after record 7, after record 200, and so on.

I didn’t think it would be that hard to find an answer. I posted the question on forums a few times, talked with a couple Corona “gurus” but obviously not the right ones. The advice I got back was “Corona isn’t really good for business apps…” Great advice. Not any help though.

So I persevered and am putting this CRUD example done in Corona – Lua – Sqlite for anyone else out there that needs or wants to do some simple database create, reading, updating and deleting.

<strong>Basics:</strong>

I create a database then add a table with these fields:
<ul>
<li>Company name</li>
<li>Contact</li>
<li>Address 1</li>
<li>Address 2</li>
<li>City</li>
<li>State</li>
<li>Zip</li>
<li>Email</li>
<li>Phone</li>
<li>Fax</li>
<li>Notes</li>
</ul>
Then I populate the table with dummy data. Read the code – there’s a var you can set that says how many records to use. I tested it with 5000 records, a bit more than most apps on a cell phone would need I think.

Next I go to a screen that lists the Company Name and Contact. You can scroll up and down, pick one and view it’s details and then update or change any information. There’s a delete button and also an add button.

I’ve also added the ability to retrieve the information sorted by Company name or Contact.

Though it is a fully working example, you’d probably want to pretty it up and rearrange things to make it useful, but the mechanics are there for you to browse and hopefully easily find some of the things that I had to spend a ton of time digging for.

Is it great code? I’m sure there’s a lot of room for improvement and many places you’ll say “I wouldn’t have done it that way.” But, go in and do it your way.

The piece that was a real pain in the butt was that passing the table row ID. What I ended up doing was to create a global array and as I displayed the list on the screen I entered each record into the array. That way the array was in the same order as the screen list so if I touched row 7 and it had say, record 99, I could reference the holding array item 7 and pull out the ID 99. Then the called screen could reference the array item 7, get the ID 99, do an sql pulling record with ID=99 and work on the correct data.

It works. It’s what I would consider kludgy – but it works.

Here’s a link to a zip file of the app, it’s a Corona app done in Lua Glider, but you should be able to use most anything that does Corona to open an compile it.

<a href=”https://leonzak.com/wp-content/uploads/2013/11/MyTest-Database-App.zip”>Click here for MyTest Database App in zip format</a>