Inheritance: System.Exception
        private void Execute(string query, params object[] parameters)
        {
            Sqlite3Statement statement = null;

            try
            {
                Result r = (Result)Enum.Parse(typeof(Result), Sqlite3.sqlite3_prepare_v2(Handle, query, out statement).ToString());
                if (r != Result.OK && r != Result.Done && r != Result.Row)
                {
                    throw Sqlite3Exception.New(r, string.Format("Error executing statement {0}", r));
                }
                BindData(statement, parameters);
                r = (Result)Enum.Parse(typeof(Result), Sqlite3.sqlite3_step(statement).ToString());
                if (r != Result.OK && r != Result.Done && r != Result.Row)
                {
                    throw Sqlite3Exception.New(r, string.Format("Error executing statement {0}", r));
                }
            }
            finally
            {
                if (statement != null)
                {
                    Sqlite3.sqlite3_finalize(statement);
                }
            }
        }
        private Sqlite3Statement ExecuteQuery(string query, params object[] parameters)
        {
            Sqlite3Statement statement;
            Result           r = (Result)Enum.Parse(typeof(Result), Sqlite3.sqlite3_prepare_v2(Handle, query, out statement).ToString());

            if (r != Result.OK && r != Result.Done && r != Result.Row)
            {
                throw Sqlite3Exception.New(r, string.Format("Error executing statement {0}", r));
            }
            BindData(statement, parameters);
            return(statement);
        }
        private void SetupDatabase()
        {
            SQLitePCL.Batteries.Init();

            string dbPath = Path.Combine(PCLStorage.FileSystem.Current.LocalStorage.Path, DB_FILE_NAME);

            var r = Sqlite3.sqlite3_open(dbPath, out Handle);

            string createDatasetTable = "CREATE TABLE IF NOT EXISTS " + TABLE_DATASETS + "("
                                        + DatasetColumns.IDENTITY_ID + " TEXT NOT NULL,"
                                        + DatasetColumns.DATASET_NAME + " TEXT NOT NULL,"
                                        + DatasetColumns.CREATION_TIMESTAMP + " TEXT DEFAULT '0',"
                                        + DatasetColumns.LAST_MODIFIED_TIMESTAMP + " TEXT DEFAULT '0',"
                                        + DatasetColumns.LAST_MODIFIED_BY + " TEXT,"
                                        + DatasetColumns.STORAGE_SIZE_BYTES + " INTEGER DEFAULT 0,"
                                        + DatasetColumns.RECORD_COUNT + " INTEGER DEFAULT 0,"
                                        + DatasetColumns.LAST_SYNC_COUNT + " INTEGER NOT NULL DEFAULT 0,"
                                        + DatasetColumns.LAST_SYNC_TIMESTAMP + " INTEGER DEFAULT '0',"
                                        + DatasetColumns.LAST_SYNC_RESULT + " TEXT,"
                                        + "UNIQUE (" + DatasetColumns.IDENTITY_ID + ", "
                                        + DatasetColumns.DATASET_NAME + ")"
                                        + ")";

            if (r != Sqlite3.SQLITE_OK)
            {
                throw Sqlite3Exception.New((Result)Enum.Parse(typeof(Result), r.ToString()), string.Format("Could not open database file: {0} ({1})", dbPath, r));
            }

            Execute(createDatasetTable);

            string createRecordsTable = "CREATE TABLE IF NOT EXISTS " + TABLE_RECORDS + "("
                                        + RecordColumns.IDENTITY_ID + " TEXT NOT NULL,"
                                        + RecordColumns.DATASET_NAME + " TEXT NOT NULL,"
                                        + RecordColumns.KEY + " TEXT NOT NULL,"
                                        + RecordColumns.VALUE + " TEXT,"
                                        + RecordColumns.SYNC_COUNT + " INTEGER NOT NULL DEFAULT 0,"
                                        + RecordColumns.LAST_MODIFIED_TIMESTAMP + " TEXT DEFAULT '0',"
                                        + RecordColumns.LAST_MODIFIED_BY + " TEXT,"
                                        + RecordColumns.DEVICE_LAST_MODIFIED_TIMESTAMP + " TEXT DEFAULT '0',"
                                        + RecordColumns.MODIFIED + " INTEGER NOT NULL DEFAULT 1,"
                                        + "UNIQUE (" + RecordColumns.IDENTITY_ID + ", " + RecordColumns.DATASET_NAME
                                        + ", " + RecordColumns.KEY + ")"
                                        + ")";

            Execute(createRecordsTable);
        }