Ejemplo n.º 1
0
        /// <summary>
        /// creates an option entry with specified name(s) and descriptoin
        /// </summary>
        /// <param name="section">the section that contains this new entry</param>
        /// <param name="s">the name of the entry</param>
        /// <param name="description">the descriptiion of the entry.</param>
        internal OptionEntry(OptionMap section, string s, string description)
        {
            OptionMapDataset4 ds      = section.ds;
            object            name_id = ds.name.GetNameID(section.db, s);   // section.names[s];
            object            ID;

            if (section.root.option_map_key_type == typeof(Guid))
            {
                DataRow row = ds.CreateOption(section.db, ID = DsnConnection.GetGUID(section.db), section.ID, name_id);
                if (description != null)
                {
                    row["description"] = description;
                }
            }
            else
            {
                DataRow row = ds.CreateOption(section.db, section.ID, name_id);
                ID = row[ds.map.option_idColumn];
                if (description != null)
                {
                    row["description"] = description;
                }
            }
            sub_options  = new OptionMap(this, ID);
            this.section = section;
            m_name       = s;
        }
Ejemplo n.º 2
0
        internal OptionEntry(OptionMap section, string s)
        {
            OptionMapDataset4 ds      = section.ds;
            object            name_id = ds.name.GetNameID(section.db, s);   // section.names[s];
            object            ID;

            if (section.root.option_map_key_type == typeof(Guid))
            {
                ds.CreateOption(section.db, ID = DsnConnection.GetGUID(section.db), section.ID, name_id);
            }
            else
            {
                ID = ds.CreateOption(section.db, section.ID, name_id);
            }
            sub_options  = new OptionMap(this, ID);
            this.section = section;
            m_name       = s;
            return;

#if asdfasdf
            object name_id = section.names[s];
            object option_id;
            if (!section.fallback_ini)
            {
                option_id = section.db.KindExecuteInsert("insert into " + OptionMap.Prefix + "map(parent_option_id,name_id) values('" + section.ID + "','" + name_id + "')");
            }
            else
            {
                option_id = 1;
            }
            this.section = section;
            sub_options  = new OptionMap(this, option_id);
            m_name       = s;
#endif
        }
Ejemplo n.º 3
0
 public object GetNameID(DsnConnection dsn, String name)
 {
     DataRow[] row = Select(nameColumn.ColumnName + "='" + name + "'");
     if (row.Length == 0)
     {
         OptionMapDataset4 ds      = this.DataSet as OptionMapDataset4;
         DataRow           newname = NewRow();
         newname[name_idColumn] = DsnConnection.GetGUID(dsn);
         newname[nameColumn]    = name;
         Rows.Add(newname);
         ds.ScheduleCommit(dsn, this);
         return(newname[name_idColumn]);
     }
     return(row[0][name_idColumn]);
 }
Ejemplo n.º 4
0
        static void table_TableNewRow(object sender, DataTableNewRowEventArgs e)
        {
            MySQLDataTable     that   = e.Row.Table as MySQLDataTable;
            MySQLDataTable <T> that_t = e.Row.Table as MySQLDataTable <T>;
            IXDataTable        xthat  = e.Row.Table as IXDataTable;
            DsnConnection      conn   = null;

            if (that != null)
            {
                conn = that.connection;
            }
            else if (that_t != null)
            {
                conn = that_t.connection;
            }
            if (xthat != null)
            {
                e.Row[xthat.PrimaryKeyName] = DsnConnection.GetGUID(conn);
            }
            else
            {
                e.Row[XDataTable.ID(e.Row.Table)] = DsnConnection.GetGUID(conn);
            }
        }
Ejemplo n.º 5
0
        static public void AppendToDatabase(DsnConnection connection, DataTable table)
        {
            if (connection == null)
            {
                return;
            }
            String      PrimaryKeyName = XDataTable.ID(table);
            IXDataTable xdataTable     = table as IXDataTable;
            Type        key_type       = table.Columns[PrimaryKeyName].DataType;

            if (xdataTable != null)
            {
                xdataTable.filling = true;
            }
            Log.log("AppendToDatabase should check primary key type - if it's Guid, then min/max are irrelavent");
            object min_local_id = table.Compute("min(" + PrimaryKeyName + ")", null);
            object max_local_id = table.Compute("max(" + PrimaryKeyName + ")", null);

            // no rows to commit.
            if (min_local_id.GetType() == typeof(DBNull))
            {
                return;
            }

            if (key_type == typeof(Int32))
            {
                object max_real_id = connection.ExecuteScalar("select max(" + PrimaryKeyName + ") from "
                                                              + connection.sql_quote_open + table.Prefix + table.TableName + connection.sql_quote_close);
                if ((max_real_id == null) || (max_real_id.GetType() == typeof(DBNull)))
                {
                    //
                    if (Convert.ToInt32(min_local_id) != 1)
                    {
                        int n = 1;
                        foreach (DataRow row in table.Rows)
                        {
                            row[PrimaryKeyName] = n;
                            n++;
                        }
                    }
                }
                else
                {
                    if (Convert.ToInt32(max_real_id) >= Convert.ToInt32(min_local_id) && Convert.ToInt32(max_real_id) <= Convert.ToInt32(max_local_id))
                    {
                        int final_id = Convert.ToInt32(max_real_id) + table.Rows.Count + 1;
                        if (final_id < Convert.ToInt32(max_local_id))
                        {
                            int n = Convert.ToInt32(max_real_id) + 1;
                            // while moving row ID's we may duplicate, so... look ahead...
                            foreach (DataRow row in table.Rows)
                            {
                                DataRow[] conflict = table.Select(PrimaryKeyName + "=" + n);
                                if (conflict.Length > 0)
                                {
                                    int old_id = Convert.ToInt32(row[PrimaryKeyName]);
                                    conflict[0][PrimaryKeyName] = 0;
                                    row[PrimaryKeyName]         = n;
                                    conflict[0][PrimaryKeyName] = old_id;
                                }
                                else
                                {
                                    row[PrimaryKeyName] = n;
                                }
                                n++;
                            }


                            //object o = null;
                            //o.GetType();
                        }
                        else
                        {
                            int r;
                            for (r = table.Rows.Count - 1; r >= 0; r--)
                            {
                                table.Rows[r][PrimaryKeyName] = final_id;
                                final_id--;
                            }
                        }
                    }
                    else
                    {
                        int n = Convert.ToInt32(max_real_id) + 1;
                        foreach (DataRow row in table.Rows)
                        {
                            row[PrimaryKeyName] = n;
                            n++;
                        }
                    }
                }
            }
            else if (key_type == typeof(Guid))
            {
                foreach (DataRow row in table.Rows)
                {
                    row[PrimaryKeyName] = connection.GetGUID();
                }
            }
            DsnSQLUtil.InsertAllRows(connection, table);
            if (xdataTable != null)
            {
                xdataTable.filling = false;
            }
        }
Ejemplo n.º 6
0
 public static Guid GetCOMB()
 {
     return(DsnConnection.GetGUID(null));
 }