Exemplo n.º 1
0
        public void updateSchemaIfNeeded()
        {
            //db context
            var dbc = this.newContext();
            //fields
            meta_name = stringColumn("name", 150);
            meta_value = (IntColumn)intColumn("value").allowNull();
            meta_text = (StringColumn)stringColumn("text", 150).allowNull();

            //table
            tbl_meta= this.newTable("ds_meta", meta_name, meta_value, meta_text);

            //create if not exists
            dbc.create(tbl_meta);
            //look version
            int ver = currentVersion(dbc);
            if (ver == -1)
            {
                // insert version row
                dbc.insertInto(tbl_meta).Values(meta_name.value("schema version"), meta_value.value(0))
                    .execute();
                //
                ver = 0;
            }
            //
            for (int i = ver; i < schemaUpdates.Count; i++)
            {
                schemaUpdates[i].apply(this, dbc);
            }
            setSchemaVersion(schemaUpdates.Count, dbc);
            //commit
            dbc.SubmitChanges();
        }
Exemplo n.º 2
0
        ///// <summary>
        ///// adds a new fk to the table and adds the field to fields list
        ///// </summary>
        //public IntColumn addFKto(Table table)
        //{
        //    IntColumn tmp= db.intColumn( string.Format("{0}_id", table.Name));

        //    this.fields.Add(tmp);

        //    this.FKs.Add(
        //        new ForeinKey( tmp, table)
        //        );

        //    return tmp;
        //}

        /// <summary>
        /// adds a new fk to the table and adds the field to fields list, specifying it's name in the db
        /// </summary>
        public IntColumn addFKto(Table table, string name)
        {
            IntColumn tmp = db.intColumn(name);

            this.fields.Add(tmp);

            this.FKs.Add(
                new ForeinKey(tmp, table)
                );

            return(tmp);
        }
Exemplo n.º 3
0
 //extensions for datarow
 public static int getInt(this DataRow dr, IntColumn col)
 {
     return(Convert.ToInt32(dr[col.Name].ToString()));
 }