Ejemplo n.º 1
0
 public void Fill(DsnConnection dsn)
 {
     DsnSQLUtil.FillDataTable(dsn, name);
     //DsnSQLUtil.FillDataTable( dsn, map, map.option_idColumn.ColumnName + "=" + MySQLDataTable.GetSQLValue( dsn, map.option_idColumn, Guid.Empty ) );
     //OptionMapDatasetTableAdapters.option2_nameTableAdapter da = new OptionMapDatasetTableAdapters.option2_nameTableAdapter();
     //da.Fill( this.option2_name );
     //this.option2_valuesTableAdapter.Fill( this.option2_map );
     //OptionMapDatasetTableAdapters.option2_valuesTableAdapter da3 = new OptionMapDatasetTableAdapters.option2_valuesTableAdapter();
     //da3.Fill( this.option2_values );
 }
Ejemplo n.º 2
0
        public DataRow CreateOption(DsnConnection dsn, object parent_option_id, object name_id)
        {
            DataRow row = map.NewRow();

            //row[map.option_idColumn] = option_id;
            row[map.parent_option_idColumn] = parent_option_id;
            row[map.name_idColumn]          = name_id;
            map.Rows.Add(row);
            ScheduleCommit(dsn, map);
            return(row);
        }
Ejemplo n.º 3
0
        public void CreateOption(DsnConnection dsn, object option_id, object parent_option_id, object name_id, String description)
        {
            DataRow row = map.NewRow();

            row[map.option_idColumn]        = option_id;
            row[map.parent_option_idColumn] = parent_option_id;
            row[map.name_idColumn]          = name_id;
            row[map.descriptionColumn]      = description;
            map.Rows.Add(row);
            DsnSQLUtil.CommitChanges(dsn, map);
        }
Ejemplo n.º 4
0
        public DataRow CreateOption(DsnConnection dsn, object option_id, object parent_option_id, object name_id)
        {
            DataRow row = map.NewRow();

            row[map.option_idColumn]        = option_id;
            row[map.parent_option_idColumn] = parent_option_id;
            row[map.name_idColumn]          = name_id;
            map.Rows.Add(row);
            DsnSQLUtil.CommitChanges(dsn, map);
            return(row);
        }
Ejemplo n.º 5
0
 public void Commit(DsnConnection odbc)
 {
     odbc.BeginTransaction();
     foreach (DataTable m in PersistantTables)
     {
         Log.log("Commiting " + m.ToString());
         DsnSQLUtil.CommitChanges(odbc, m);
     }
     odbc.EndTransaction();
     active_dataset.AcceptChanges();
 }
Ejemplo n.º 6
0
 public MySQLDataTable(DsnConnection dsn, DataTable table)
 {
     // copy table into myself...
     connection = dsn;
     TableName  = table.TableName;
     Prefix     = table.Prefix;
     foreach (DataColumn dc in table.Columns)
     {
         Columns.Add(dc);
     }
     DsnSQLUtil.CreateDataTable(connection, this);
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Creates a table with a prefix and a name, deault columns name_id and name_name
 /// </summary>
 /// <param name="prefix">Prefix to prepend to the table name (not column names)</param>
 /// <param name="name">Table name to create and fill</param>
 /// <param name="add_default_columns">Option to add default _id and _name column</param>
 /// <param name="auto_fill">Option to auto create/fill table with data</param>
 public RegSQLDataTable(DsnConnection dsn, string prefix, string name, bool trim_info, bool auto_fill, bool add_default_name)
 {
     this.connection = dsn;
     this.TableName  = name;
     this.Prefix     = (prefix == null) ? "" : prefix;
     AddDefaultColumns(trim_info, true, add_default_name);
     if (auto_fill)
     {
         Create();
         Fill();
     }
     this.RowDeleting += new DataRowChangeEventHandler(MySQLDataTable_RowDeleting);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Creates a table with a prefix and a name, deault columns name_id and name_name
 /// </summary>
 /// <param name="prefix">Prefix to prepend to the table name (not column names)</param>
 /// <param name="name">Table name to create and fill</param>
 /// <param name="add_default_columns">Option to add default _id and _name column</param>
 /// <param name="auto_fill">Option to auto create/fill table with data</param>
 public MySQLDataTable(DsnConnection dsn, string prefix, string name, bool trim_info, bool auto_fill, bool add_default_name, bool add_default_id)
 {
     this.connection = dsn;
     this.TableName  = name;
     this.Prefix     = (prefix == null) ? "" : prefix;
     Init();
     AddDefaultColumns(trim_info, add_default_id, add_default_name);
     if (auto_fill)
     {
         DsnSQLUtil.CreateDataTable(connection, this);
         Fill();
     }
 }
Ejemplo n.º 9
0
        internal void Delete()
        {
            DsnConnection dsn = this.section.db;

            //this.section.ds.map.Delete

/*
 *                      dsn.KindExecuteNonQuery( "delete from " + OptionMap.Prefix + "values where option_id='" + this.sub_options.ID + "'" );
 *                      dsn.KindExecuteNonQuery( "delete from " + OptionMap.Prefix + "blobs where option_id='" + this.sub_options.ID + "'" );
 *                      dsn.KindExecuteNonQuery( "delete from " + OptionMap.Prefix + "map where option_id='" + this.sub_options.ID + "'" );
 */
            this.section.Remove(this);
        }
Ejemplo n.º 10
0
		public MetaMySQLRelation( DsnConnection odbc, DataSet dataSet
			, DataTable table
			, String path_from_2_to_source
			, bool add_number
			, bool auto_fill
			, DataColumn[] extra_data )
			: base( odbc, dataSet
			, table
			, path_from_2_to_source
			, add_number
			, auto_fill
			, extra_data )
		{
		}
Ejemplo n.º 11
0
 public object GetNameID(DsnConnection dsn, String name)
 {
     DataRow[] row = Select(nameColumn.ColumnName + "='" + name + "'");
     if (row.Length == 0)
     {
         DataRow newname = NewRow();
         //newname[name_idColumn] = 0; // auto fill
         newname[nameColumn] = name;
         Rows.Add(newname);
         DsnSQLUtil.CommitChanges(dsn, this);
         return(newname[name_idColumn]);
     }
     return(row[0][name_idColumn]);
 }
Ejemplo n.º 12
0
 public MySQLNameTable(DsnConnection dsn, string prefix, string name, bool trim_info, bool auto_fill, bool simple_name)
     : base(dsn, prefix, name, true, trim_info, false)
 {
     // otherwise non-simple will be added by base initilalizer.
     if (simple_name)
     {
         DataColumn dc = this.Columns.Add(simple_name ? "name" : XDataTable.Name(this), typeof(string));
         dc.Unique = true;
     }
     if (auto_fill)
     {
         DsnSQLUtil.CreateDataTable(connection, this);
         Fill();
     }
 }
Ejemplo n.º 13
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.º 14
0
 /// <summary>
 /// Replaces the current connection with the passed connection, and invokes Fill.
 /// </summary>
 /// <param name="new_connection"></param>
 /// <param name="fill">if set, will invoke Fill()</param>
 /// <param name="sync">if set, will sync to database (relation table, probably the current relations more accurate</param>
 public void Reconnect(DsnConnection new_connection, bool fill, bool sync)
 {
     connection = new_connection;
     DsnSQLUtil.CreateDataTable(connection, this);
     if (fill)
     {
         this.BeginLoadData();
         Clear();
         Fill();
         this.EndLoadData();
     }
     else if (sync)
     {
         SyncToDatabase(new_connection);
     }
 }
Ejemplo n.º 15
0
 void ScheduleCommit(DsnConnection dsn, DataTable table)
 {
     if (commit_pending.IndexOf(table) < 0)
     {
         pending_dsn = dsn;
         commit_pending.Add(table);
         if (delay_commit == null)
         {
             delay_commit          = new Timer();
             delay_commit.Tick    += DelayCommit;
             delay_commit.Interval = 250;
             delay_commit.Start();
         }
     }
     Log.log("Kicking timer.");
     target_tick = DateTime.Now.AddMilliseconds(250);
 }
Ejemplo n.º 16
0
 //OptionMapDatasetTableAdapters.option2_mapTableAdapter map_adapter = new OptionMapDatasetTableAdapters.option2_mapTableAdapter();
 public DataRow[] LoadMore(DsnConnection dsn, object uid)
 {
     DataRow[] rows;
     DsnSQLUtil.FillDataTable(dsn, map, map.parent_option_idColumn.ColumnName + "=" + DsnSQLUtil.GetSQLValue(dsn, map.option_idColumn, uid));
     if (DsnSQLUtil.Compare(typeof(Guid), uid, Guid.Empty))
     {
         rows = map.Select(map.option_idColumn.ColumnName + "='" + uid.ToString() + "'");
         if (rows.Length == 0)
         {
             CreateOption(dsn, uid, uid, name.GetNameID(dsn, "."));
         }
         rows = map.Select(map.parent_option_idColumn.ColumnName + "='" + uid.ToString() + "'and " + map.option_idColumn.ColumnName + "<>'" + uid.ToString() + "'");
     }
     else
     {
         rows = map.Select(map.parent_option_idColumn.ColumnName + "='" + uid.ToString() + "'");
     }
     return(rows);
 }
Ejemplo n.º 17
0
 public static Guid GetGUID(DsnConnection dsn)
 {
     if (dsn == null)
     {
         return(Guid.NewGuid());
     }
     if ((dsn.DbMode == DsnConnection.ConnectionMode.Odbc &&
          dsn.DbFlavor == DsnConnection.ConnectionFlavor.MySqlNative)
         )
     {
         Guid   id         = Guid.NewGuid();
         Byte[] bytes      = id.ToByteArray();
         long   ticks      = DateTime.Now.Ticks / 10000;
         Byte[] tick_bytes = BitConverter.GetBytes(ticks);
         for (int n = 0; n < 6; n++)
         {
             bytes[0] = tick_bytes[5 - n];
         }
         Guid COMB = new Guid(bytes);
         return(COMB);
     }
     else if (dsn.DbMode == DsnConnection.ConnectionMode.SQLServer ||
              (dsn.DbMode == DsnConnection.ConnectionMode.Odbc &&
               dsn.DbFlavor == DsnConnection.ConnectionFlavor.SQLServer))
     {
         Guid   id         = Guid.NewGuid();
         Byte[] bytes      = id.ToByteArray();
         long   ticks      = DateTime.Now.Ticks / 10000;
         Byte[] tick_bytes = BitConverter.GetBytes(ticks);
         for (int n = 0; n < 6; n++)
         {
             bytes[15 - n] = tick_bytes[n];
         }
         Guid COMB = new Guid(bytes);
         return(COMB);
     }
     else
     {
         Log.log("Failed to recognize how to create optimal keys for database flavor and mode.");
     }
     return(new Guid());
 }
Ejemplo n.º 18
0
 public void Fill(DsnConnection dsn)
 {
     DsnSQLUtil.FillDataTable(dsn, name);
     DsnSQLUtil.FillDataTable(dsn, map, map.parent_option_idColumn.ColumnName + "=" + DsnSQLUtil.GetSQLValue(dsn, map.option_idColumn, Guid.Empty));
     if (map.Rows.Count == 0)
     {
         DataRow map_root = map.NewRow();
         map_root[map.option_idColumn]        = Guid.Empty;
         map_root[map.parent_option_idColumn] = Guid.Empty;
         map_root[map.descriptionColumn]      = "Option Map Root";
         map_root[map.name_idColumn]          = name.GetNameID(dsn, ".");
         map.Rows.Add(map_root);
         ScheduleCommit(dsn, map);
     }
     //OptionMapDatasetTableAdapters.option2_nameTableAdapter da = new OptionMapDatasetTableAdapters.option2_nameTableAdapter();
     //da.Fill( this.option2_name );
     //this.option2_valuesTableAdapter.Fill( this.option2_map );
     //OptionMapDatasetTableAdapters.option2_valuesTableAdapter da3 = new OptionMapDatasetTableAdapters.option2_valuesTableAdapter();
     //da3.Fill( this.option2_values );
 }
Ejemplo n.º 19
0
        /// <summary>
        /// Creates and opens a connection to the MySQL DSN.  Throws an exception if connection could not be open
        /// </summary>
        static StaticDsnConnection()
        {
            String attempting = null;

            try
            {
                _dsn = new DsnConnection(attempting = INI.Default[Options.ProgramName]["ODBC", "MySQL"]);
                _dsn.disable_logging = INI.Default[Options.ProgramName]["Static database connection logging disabled", 1].Bool;
            }
            catch (Exception exc)
            {
                if (_dsn == null)
                {
                    MessageBox.Show("Cannot open database [" + attempting + "].\n"
                                    + "Database Connection Setting in...\n{" + INI.Default.file + "}\n[" + Options.ProgramName + "]\nODBC=" + attempting + "\n\n"
                                    + exc.Message
                                    );
                    throw new NullReferenceException("Failed to connect to database", exc);
                }
            }
        }
Ejemplo n.º 20
0
 /// <summary>
 /// provides the database conneciton also.
 /// </summary>
 /// <param name="db"></param>
 internal OptionMap(DsnConnection db)
 {
     this._db = db;
     if (db != null)
     {
         db.disable_logging = false;
     }
     this.fallback_ini = false;
     SetupTables();
     this.read_branch = true;
     // don't know the type until we create the table storage
     if (root.option_map_key_type == typeof(Guid))
     {
         ID = Guid.Empty;
     }
     else
     {
         ID = (int)0;
     }
     ReadBranch();
 }
Ejemplo n.º 21
0
 public void SetConnection(DsnConnection dsn, bool auto_create)
 {
     if (connection == null)
     {
         connection = dsn;
         if (dsn != null)
         {
             if (auto_create)
             {
                 DsnSQLUtil.CreateDataTable(connection, this);
             }
         }
     }
     else
     {
         connection = dsn;
         if (auto_create)
         {
             DsnSQLUtil.CreateDataTable(connection, this);
         }
     }
 }
Ejemplo n.º 22
0
        public String GetValue(DsnConnection dsn, object option_id)
        {
            DataRow[] row = values.Select(values.option_idColumn.ColumnName + "='" + option_id.ToString() + "'");
            if (row.Length == 0)
            {
                List <DataRow> rows = DsnSQLUtil.FillDataTable(dsn, values, values.option_idColumn.ColumnName + "=" + DsnSQLUtil.GetSQLValue(dsn, values.option_idColumn, option_id), "segment");
                if (rows == null || rows.Count == 0)
                {
#if asdfasdf
                    DataRow newval = values.NewRow();
                    newval[values.option_idColumn] = option_id;
                    newval[values.stringColumn]    = default_value;
                    values.Rows.Add(newval);
                    MySQLDataTable.CommitChanges(dsn, values);
                    return(default_value);
#endif
                    //throw new Exception( "soemthign bad" );
                    return(null);
                }
                else
                {
                    String tmp = null;
                    foreach (DataRow row_add in rows)
                    {
                        tmp += row_add[values.stringColumn].ToString();
                    }
                    return(tmp);
                }
            }
            else
            {
                String tmp = null;
                foreach (DataRow row_add in row)
                {
                    tmp += row_add[values.stringColumn].ToString();
                }
                return(tmp);
            }
        }
Ejemplo n.º 23
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.º 24
0
        public void SetValue(DsnConnection dsn, object option_id, String value)
        {
            int segment = 0;

            DataRow[] row = values.Select(values.option_idColumn.ColumnName + "='" + option_id.ToString() + "'");
            if (row.Length == 0)
            {
                List <DataRow> rows = DsnSQLUtil.FillDataTable(dsn, values, values.option_idColumn.ColumnName + "=" + DsnSQLUtil.GetSQLValue(dsn, values.option_idColumn, option_id), "segment");
                if (rows == null || rows.Count == 0)
                {
                    if (value.Length > 99)
                    {
                        String tmp = value;
                        while (tmp.Length > 99)
                        {
                            DataRow newval = values.NewRow();
                            newval[values.option_idColumn] = option_id;
                            newval[values.stringColumn]    = tmp.Substring(0, 99);
                            tmp = tmp.Substring(99);
                            newval[values.segmentColumn] = segment++;
                            values.Rows.Add(newval);
                        }
                        value = tmp;
                    }
                    if (value.Length > 0)
                    {
                        DataRow newval = values.NewRow();
                        newval[values.option_idColumn] = option_id;
                        newval[values.stringColumn]    = value;
                        newval[values.segmentColumn]   = segment++;
                        values.Rows.Add(newval);
                    }
                }
                else
                {
                    while (value.Length > 99)
                    {
                        if (segment < rows.Count)
                        {
                            rows[segment++][values.stringColumn] = value.Substring(0, 99);
                        }
                        else
                        {
                            DataRow newval = values.NewRow();
                            newval[values.option_idColumn] = option_id;
                            newval[values.stringColumn]    = value.Substring(0, 99);
                            newval[values.segmentColumn]   = segment++;
                            values.Rows.Add(newval);
                        }
                        value = value.Substring(99);
                    }
                    if (segment < rows.Count)
                    {
                        rows[segment++][values.stringColumn] = value;
                    }
                    else
                    {
                        DataRow newval = values.NewRow();
                        newval[values.option_idColumn] = option_id;
                        newval[values.stringColumn]    = value.Substring(0, 99);
                        newval[values.segmentColumn]   = segment++;
                        values.Rows.Add(newval);
                    }
                    while (segment < rows.Count)
                    {
                        rows[segment++].Delete();
                    }
                }
            }
            else
            {
                while (value.Length > 99)
                {
                    if (segment < row.Length)
                    {
                        row[segment++][values.stringColumn] = value.Substring(0, 99);
                    }
                    else
                    {
                        DataRow newval = values.NewRow();
                        newval[values.option_idColumn] = option_id;
                        newval[values.stringColumn]    = value.Substring(0, 99);
                        newval[values.segmentColumn]   = segment++;
                        values.Rows.Add(newval);
                    }
                    value = value.Substring(99);
                }
                if (segment < row.Length)
                {
                    row[segment++][values.stringColumn] = value;
                }
                else
                {
                    DataRow newval = values.NewRow();
                    newval[values.option_idColumn] = option_id;
                    newval[values.stringColumn]    = value;
                    newval[values.segmentColumn]   = segment++;
                    values.Rows.Add(newval);
                }
                while (segment < row.Length)
                {
                    row[segment++].Delete();
                }
            }
            ScheduleCommit(dsn, values);
        }
Ejemplo n.º 25
0
 public MySQLNameTable(DsnConnection dsn, string prefix, string name, bool trim_info, bool auto_fill)
     : base(dsn, prefix, name, true, trim_info, auto_fill, true)
 {
 }
Ejemplo n.º 26
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.º 27
0
 /// <summary>
 /// Just a normal DataTable with additional Methods?
 /// </summary>
 public MySQLDataTable(DsnConnection connection)
 {
     this.connection = connection;
     Init();
 }
Ejemplo n.º 28
0
        public static OptionMap Database(DsnConnection db)
        {
            OptionMap tmp_options = new OptionMap(db);

            return(tmp_options);
        }
Ejemplo n.º 29
0
 public static Guid GetCOMB()
 {
     return(DsnConnection.GetGUID(null));
 }
Ejemplo n.º 30
0
 public OptionNames(DsnConnection dsn)
     : base(dsn, OptionMap.Prefix, NameColumn, true, true)
 {
 }