public long IndexOf(object item_id)
        {
            lock (this) {
                if (rows == 0)
                {
                    return(-1);
                }

                long target_id = connection.Query <long> (select_single_command, item_id);
                if (target_id == 0)
                {
                    return(-1);
                }
                return(target_id - FirstOrderId);
            }
        }
Exemple #2
0
        protected virtual void CheckVersion()
        {
            if (connection.TableExists(HyenaTableName))
            {
                using (IDataReader reader = connection.Query(SelectVersionSql(TableName))) {
                    if (reader.Read())
                    {
                        int table_version = reader.GetInt32(0);
                        if (table_version < ModelVersion)
                        {
                            MigrateTable(table_version);
                            UpdateVersion(TableName, ModelVersion);
                        }
                    }
                    else
                    {
                        InsertVersion(TableName, ModelVersion);
                    }
                }
                int db_version = connection.Query <int> (SelectVersionSql(HYENA_DATABASE_NAME));
                if (db_version < DatabaseVersion)
                {
                    MigrateDatabase(db_version);
                    UpdateVersion(HYENA_DATABASE_NAME, DatabaseVersion);
                }
            }
            else
            {
                connection.Execute(String.Format(
                                       @"CREATE TABLE {0} (
                        id INTEGER PRIMARY KEY,
                        name TEXT UNIQUE,
                        version INTEGER)",
                                       HyenaTableName)
                                   );

                InsertVersion(HYENA_DATABASE_NAME, DatabaseVersion);
                InsertVersion(TableName, ModelVersion);
            }
        }
        public long IndexOf(string where_fragment, long offset)
        {
            if (String.IsNullOrEmpty(where_fragment))
            {
                return(-1);
            }

            if (!where_fragment.Equals(last_indexof_where_fragment))
            {
                last_indexof_where_fragment = where_fragment;

                if (!where_fragment.Trim().ToLower().StartsWith("and "))
                {
                    where_fragment = " AND " + where_fragment;
                }

                string sql = String.Format("{0} {1} LIMIT ?, 1", select_str, where_fragment);
                indexof_command = new HyenaSqliteCommand(String.Format(sql, null, null));
            }

            lock (this) {
                using (IDataReader reader = connection.Query(indexof_command, offset)) {
                    if (reader.Read())
                    {
                        long target_id = (long)reader[reader.FieldCount - 2];
                        if (target_id == 0)
                        {
                            return(-1);
                        }
                        return(target_id - FirstOrderId);
                    }
                }

                return(-1);
            }
        }