Thursday, May 14, 2009

Easy SQLite wrapper for the iPhone

SQLite is great. It is small, fast and easy to set up. However, if you are writing an iPhone app that needs it, you're in for a bit of learning. You will need to learn what API calls to make and when to make them, usually by going over example code and using trial and error. I am introducing an open source SQLite C++ wrapper that will allow you to use the database without having to learn the SQLite API. It may save you several days of work.

The wrapper is just two C++ files, has a MIT style license and is platform independent so it's not just for iPhone. You will still need to learn the quirky SQLite SQL syntax however.

You can download it here.

Creating a database and table
#include "sdsqlite.h"

void create_db(void)
{
sd::sqlite database("mydb.db");
database << "create table if not exists work (first_name text, last_name text, hours real)";
}


Database insertion
#include "sdsqlite.h"

struct work_data { char* first; char* last; float hours; };

work_data wdata[] = {
{"Joe", "Smith", 2.5},
...
};

void insert_rows(void)
{
try
{
sd::sqlite database("mydb.db"); // open the db with the table already created

sd::sql insert_query(database); // build an sql query
insert_query << "insert into work (first_name, last_name, hours) VALUES(?, ?, ?)";

database << "begin transaction";// create a transaction for speed

// insert data (sdsqlite will auto-detect data type and execure query)
for(int i=0;i<sizeof(wdata)/sizeof(work_data);++i)
insert_query << wdata[i].first << wdata[i].last << wdata[i].hours;

database << "commit transaction";// complete transaction
}
catch(sd::db_error& err)
{
// do something with error
}
}


Database extraction
#include "sdsqlite.h"

void extract_name(const std::string& name)
{
try
{
sd::sqlite database("mydb.db"); // open the db with the table already created

// select all names that begin with the contents of the "name" variable
sd::sql select_query(database);
select_query << "select first_name, last_name, hours from work where first_name like ?" << name + '%';

// extract the matching rows
float hours;
std::string first, last;
while(select_query.step())
{
select_query >> first >> last >> hours;

// do something with the data
}
}
catch(sd::db_error& err)
{
// do something with error
}
}

Tuesday, May 12, 2009

Super Deadly Studios Introduction

Super Deadly Studios was created to help developers create great iPhone apps in less time. The purpose of this blog is to share my experiences with developing my own and helping other developers make great apps for the iPhone. I will be revealing more on how Super Deadly intends to make iPhone development easier over the next few posts but first I'd like to introduce myself.

Background

My name is Matt Giger and I'm an experienced developer and have been programming computers for a living for the past 25 years. I've made over a million dollars selling my product EarthBrowser as shareware with a very minimal advertising budget. There are many lessons that I've learned in product development, effective marketing and putting together a polished product that I'd like to share with others.

Apple Computer

I am a die-hard Macintosh fan and developer since I began programming on the first 128K Macintosh at Reed College in 1985. I've been rooting for Apple to succeed for what seems like forever and am very happy to see the success Apple is now having with first the iPod and more significantly the iPhone. I've seen many new technologies over the years and have become quite jaded to them since the mid 1990s. However the iPhone has gotten me excited like no other technology since I got my first Vic 20 computer.

iPhone Gold Rush

There has been a huge "gold rush" to develop for the iPhone over the past year. However it is a very difficult prospect to be successful on the iPhone for a variety of reasons, mainly that there are tens of thousands of apps out there competing for attention. Part of the problem is because Apple is allowing a lot of "junk" apps on the store. I think that is a big problem for them but one I can't see a better solution for, Apple shouldn't be the one who decides what is junk.

Zoltar the iPhone Fortune Teller



Select a card from one of five categories and Zoltar will do an animated divination on his magic crystal ball. He then will speak your fortune to you from a set of over 100 fortunes based, in part, on the minor arcana of the Tarot deck. You can rotate him around by dragging your finger or zoom in and out with the standard iPhone pinching gesture. It was a really fun first project which allowed me to test the limits of the iPhone hardware. The model of Zoltar was created in 3d Studio Max and has over 10,000 polygons and renders at about 30 frames per second which is impressive for the iPhone.



Game Engine

The 3d game engine that powers Zoltar has been refined over the past 10 years from the EarthBrowser virtual earth project. It uses a kernel architecture to manage frame, time and asynchronous tasks. It supports several 3d object formats and has a highly optimized and fast particle system generator. It currently uses the Lua scripting language but I am in the process of changing that over to Javascript as the scripting language.

I'll have more to say on development of the game engine in future posts.