Inheritance: System.ComponentModel.Component
        private static string InitSnapshotStoreSql(string tableName, string schemaName = null)
        {
            if (string.IsNullOrEmpty(tableName)) throw new ArgumentNullException("tableName", "Akka.Persistence.PostgreSql snapshot store table name is required");
            schemaName = schemaName ?? "public";

            var cb = new NpgsqlCommandBuilder();
            return string.Format(SqlSnapshotStoreFormat, cb.QuoteIdentifier(schemaName), cb.QuoteIdentifier(tableName), cb.UnquoteIdentifier(schemaName), cb.UnquoteIdentifier(tableName));
        }
Ejemplo n.º 2
0
 public static void Save()
 {
     MyConnection.ConnectionString = connectionStr;
        MyConnection.Open();
        string sql = String.Format(zapytanie);
        NpgsqlDataAdapter da = new NpgsqlDataAdapter(sql, MyConnection);
        NpgsqlCommandBuilder builder = new NpgsqlCommandBuilder(da);
        da.Update(newdt);
        MyConnection.Close();
 }
Ejemplo n.º 3
0
        /// <summary>
        /// DataSet ---NpgsqlDataAdapter ---Database
        /// </summary>
        public NpgsqlDataAdapter GetDataAdapter(string strSQL)
        {
            // Use NpgsqlCommandBuilder and SelectCommand--->Auto generate InsertCommand UpdateCommand DeleteCommand
              try
              {
              m_gCommnd.CommandText = strSQL;
              NpgsqlDataAdapter dataAdapter = new NpgsqlDataAdapter(m_gCommnd);//associate
              //InsertCommand  UpdateCommand DeleteCommand SelectCommand = m_sqlCommand;

              // Initialize the InsertCommand UpdateCommand DeleteCommand of NpgsqlDataAdapter by NpgsqlCommandBuilder.
              NpgsqlCommandBuilder cb = new NpgsqlCommandBuilder(dataAdapter);
              dataAdapter.InsertCommand = cb.GetInsertCommand();
              dataAdapter.UpdateCommand = cb.GetUpdateCommand();
              dataAdapter.DeleteCommand = cb.GetDeleteCommand();
              return dataAdapter;
              }
              catch (System.Exception ex)
              {
              MessageBox.Show(ex.ToString());
              return null;
              }
        }
Ejemplo n.º 4
0
        public frmConta()
        {
            InitializeComponent();
            string con = "Server=localhost;Port=5432;User Id=postgres;Password=postgres;Database=csharp;";
            connection = new NpgsqlConnection(con);
            connection.Open();
            listOnGrid();
            string command = "SELECT id, descricao, contasuperior, nroconta FROM tblcontas";
            dataAdapter = new NpgsqlDataAdapter(command, connection);
            //dataAdapter.Fill(ds, "Data");
            //dataGridView1.DataSource = ds;
            //dataGridView1.DataMember = "Data";

            dataGridView1.DataSource = bindingSource1;

            commandBuilder = new NpgsqlCommandBuilder(dataAdapter);

            table = new DataTable();
            table.Locale = System.Globalization.CultureInfo.InvariantCulture;
            dataAdapter.Fill(table);
            bindingSource1.DataSource = table;
        }
Ejemplo n.º 5
0
        private void sparaDatabas()
        {
            try
            {
                NpgsqlCommandBuilder cb = new NpgsqlCommandBuilder(da);
                da.Update(dt);
            }
            catch (Exception ex)
            {

            }
        }
Ejemplo n.º 6
0
        public void GetUpdateCommand()
        {
            using (var da = new NpgsqlDataAdapter("SELECT field_pk, field_int4 FROM data", Conn))
            {
                using (var cb = new NpgsqlCommandBuilder(da))
                {
                    var updateCommand = cb.GetUpdateCommand(true);
                    da.UpdateCommand = updateCommand;

                    var ds = new DataSet();
                    da.Fill(ds);

                    var table = ds.Tables[0];
                    var row = table.Rows.Add();
                    row["field_pk"] = 1;
                    row["field_int4"] = 1;
                    da.Update(ds);

                    row["field_int4"] = 2;
                    da.Update(ds);

                    row.Delete();
                    da.Update(ds);
                }
            }
        }
Ejemplo n.º 7
0
        public int SaveDataSet(DataSet changes, bool updateUserInfo, string selectSql, NpgsqlParameter[] parameters)
        {
            using(NpgsqlTransaction trans = Connection.BeginTransaction())
            {
                try
                {
                    int result = 0;
                    using(NpgsqlCommand command = CreateCommand(selectSql))
                    using(NpgsqlDataAdapter adapter = new NpgsqlDataAdapter(command))
                    {
                        foreach(NpgsqlParameter param in parameters)
                            command.Parameters.Add(param);

                        using(NpgsqlCommandBuilder cb = new NpgsqlCommandBuilder(adapter))
                        {
                            foreach(DataTable table in changes.Tables)
                            {
                                if(updateUserInfo)
                                    UpdateUserInfo(table);
                                try
                                {
                                    result += adapter.Update(table);
                                }
                                catch(DBConcurrencyException cerr)
                                {
                                    StringBuilder sb = new StringBuilder();
                                    sb.AppendLine("<!--HTML--><HTML><HEAD><TITLE>Chyba - řádek byl změněn</TITLE></HEAD><BODY>");
                                    sb.AppendLine("<BIG><B>Řádek byl od doby posledního načtení změněn</B></BIG><BR />");
                                    sb.Append("<B>Zpráva chyby:</B> " + cerr.Message + "<BR />");
                                    sb.Append("<B>Select SQL:</B><BR /><CODE>" + selectSql + "</CODE><BR />");
                                    //sb.AppendLine("Select SQL: " + adapter.SelectCommand.CommandText);
                                    //sb.AppendLine("Update SQL: " + adapter.UpdateCommand.CommandText);
                                    //sb.AppendLine("Insert SQL: " + adapter.InsertCommand.CommandText);
                                    //sb.AppendLine("Delete SQL: " + adapter.DeleteCommand.CommandText);
                                    sb.AppendLine("<B>Řádek:</B><BR /><TABLE border=\"1\"><TR><TD><B>Sloupec</B></TD><TD><B>Původní hodnota</B></TD><TD><B>Nová hodnota</B></TD><TD><B>Typ</B></TD></TR>");
                                    foreach(DataColumn col in table.Columns)
                                    {
                                        object orig = cerr.Row[col, DataRowVersion.Original];
                                        object current = cerr.Row[col, DataRowVersion.Current];
                                        bool is_changed = (orig != null) ? (!orig.Equals(current)) : ((current != null) ? (!current.Equals(orig)) : (current != orig));
                                        sb.Append("<TR><TD>");
                                        if(is_changed) sb.Append("<B>");
                                        sb.Append(col.ColumnName);
                                        if(is_changed) sb.Append("</B>");
                                        sb.Append("</TD><TD>");
                                        WriteValue(sb, orig);
                                        sb.Append("</TD><TD>");
                                        WriteValue(sb, current);
                                        sb.Append("</TD><TD>");
                                        sb.Append(col.DataType.Name);
                                        sb.AppendLine("</TD></TR>");
                                    }
                                    sb.Append("</TABLE></BODY></HTML>");
                                    throw new SoapException(sb.ToString(), SoapException.ServerFaultCode);
                                }
                            }
                        }
                    }
                    trans.Commit();
                    return result;
                }
                catch
                {
                    trans.Rollback();
                    throw;
                }
            }
        }
Ejemplo n.º 8
0
        public NpgsqlDataAdapter DataAdapterCustom(int intID)
        {
            string selectCommand = @"select 
	                                 ecc.custom_columns_id, 
	                                 ecc.custom_column_name,
                                     ecc.custom_column_data_type
                                    from experiment_custom_columns ecc
                                    where ecc.ex_id = :id";
            adapter = new Npgsql.NpgsqlDataAdapter(selectCommand, GlobalVariables.Connection);
            NpgsqlCommandBuilder commandBuilder = new NpgsqlCommandBuilder(adapter);
            adapter.SelectCommand.Parameters.Add(new NpgsqlParameter("id", NpgsqlDbType.Integer));
            adapter.SelectCommand.Parameters[0].Value = intID;
            return adapter;
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            try
            {
                var options = new Options();
                if (CommandLine.Parser.Default.ParseArguments(args, options))
                {

                    string oldName = options.OldName;
                    string newName = options.NewName;
                    string newSlaveOid = "";
                    string newSlaveAddress = options.NewSlaveAddress;
                    string oldSlaveOid = "";
                    string findStr = options.FindStr;
                    string replStr = options.ReplStr;
                    Dictionary<string, string> findreplace = new Dictionary<string, string>();
                    var find = findStr.Split(',');
                    var replace = replStr.Split(',');
                    if (find.Length != replace.Length)
                    {
                        throw new Exception("Must have equal numbers of find and replace tokens");
                    }
                    for (int i = 0; i < find.Length; i++)
                    {
                        findreplace.Add(find[i], replace[i]);
                    }

                    DataSet ds = new DataSet();
                    DataTable dt = new DataTable();

                    //our database connection string
                    string connectionString = string.Format("Server=localhost;port=5432;User Id={0};Password={1};Database=SYSCFG;", options.Username, options.Password);
                    NpgsqlConnection conn = new NpgsqlConnection(connectionString);
                    PrintVerbose("Connecting to database...", options.Verbose);
                    conn.Open();
                    //find the slave with the name that we want to copy
                    string sql = "SELECT * FROM protocol_slave_dnp WHERE entity_name = '" + oldName + "'";

                    NpgsqlDataAdapter da = new NpgsqlDataAdapter(sql, conn);
                    //get the slave data
                    ds.Reset();
                    da.Fill(ds);
                    dt = ds.Tables[0];
                    //copy the slave
                    PrintVerbose("Creating the new IED...", options.Verbose);
                    DataRow row = dt.NewRow();
                    row.ItemArray = dt.Rows[0].ItemArray.Clone() as object[];
                    oldSlaveOid = row["oid"] as string; //remember the oid, we'll need it later
                    row["oid"] = newSlaveOid = GenerateOid();
                    row["entity_name"] = newName;
                    row["slave_address"] = newSlaveAddress;
                    dt.Rows.Add(row);
                    NpgsqlCommandBuilder comb = new NpgsqlCommandBuilder(da);
                    NpgsqlCommand insCommand = comb.GetInsertCommand(true);
                    da.InsertCommand = insCommand;
                    //insert the slave
                    da.Update(ds);
                    PrintVerbose("Done.", options.Verbose);
                    ////////////////////////////////////////////////////////
                    //now find the protocol address groups and copy them too
                    PrintVerbose("Getting address groups", options.Verbose);
                    sql = "SELECT * FROM protocol_address_grp_dnp WHERE protocol_slave_oid = '" + oldSlaveOid + "'";
                    da = new NpgsqlDataAdapter(sql, conn);
                    ds.Reset();
                    da.Fill(ds);
                    dt = ds.Tables[0];
                    //this is a map of old oids to new ids, so we can copy all the points in the address groups later on
                    Dictionary<string, string> prAddrGrpOids = new Dictionary<string, string>();
                    List<DataRow> rowsToAdd = new List<DataRow>();
                    //get all the address groups and make a copy
                    PrintVerbose("Copying address groups...", options.Verbose);
                    foreach (DataRow r in dt.Rows)
                    {
                        prAddrGrpOids.Add(r["oid"] as string, GenerateOid());
                        row = dt.NewRow();
                        row.ItemArray = r.ItemArray.Clone() as object[];
                        row["oid"] = prAddrGrpOids[r["oid"] as string];
                        row["prot_poll_grp_oid"] = null;
                        row["protocol_slave_oid"] = newSlaveOid;
                        rowsToAdd.Add(row);
                    }
                    //then insert the copies back into the database
                    foreach (DataRow r in rowsToAdd)
                    {
                        dt.Rows.Add(r);
                    }
                    comb = new NpgsqlCommandBuilder(da);
                    insCommand = comb.GetInsertCommand(true);
                    da.InsertCommand = insCommand;
                    da.Update(ds);
                    PrintVerbose("Done.", options.Verbose);
                    ///////////////////////////////////////////////////////////////
                    //get a list of points from protocol_address_slave that match the above protocol address group
                    PrintVerbose("Getting address group points", options.Verbose);
                    sql = "SELECT * FROM protocol_address_dnp WHERE prot_addr_grp_oid IN(" + InifyKeys(prAddrGrpOids) + ")";
                    da = new NpgsqlDataAdapter(sql, conn);
                    ds.Reset();
                    da.Fill(ds);
                    dt = ds.Tables[0];

                    //this is a map of old oids to new ids, so we can copy all the points in the address groups later on
                    Dictionary<string, string> prPointAddrOids = new Dictionary<string, string>();
                    Dictionary<string, string> prPointOids = new Dictionary<string, string>();
                    rowsToAdd = new List<DataRow>();
                    //get all the points we need to copy, and copy the new address group-point combos in advance
                    PrintVerbose("Copying group-point relationships...", options.Verbose);
                    foreach (DataRow r in dt.Rows)
                    {
                        prPointAddrOids.Add(r["oid"] as string, GenerateOid());
                        prPointOids.Add(r["slave_point_oid"] as string, GenerateOid());
                        row = dt.NewRow();
                        row.ItemArray = r.ItemArray.Clone() as object[];
                        row["oid"] = GenerateOid(); //I dont think we care about this oid
                        row["prot_addr_grp_oid"] = prAddrGrpOids[r["prot_addr_grp_oid"] as string];
                        row["slave_point_oid"] = prPointOids[r["slave_point_oid"] as string];
                        rowsToAdd.Add(row);
                    }
                    //add new rows
                    foreach (DataRow r in rowsToAdd)
                    {
                        dt.Rows.Add(r);
                    }
                    comb = new NpgsqlCommandBuilder(da);
                    insCommand = comb.GetInsertCommand(true);
                    da.InsertCommand = insCommand;
                    da.Update(ds);
                    PrintVerbose("Done", options.Verbose);
                    //////////////////////////////////////////////////////////////
                    //copy all the analog input points
                    PrintVerbose("Copying AIs...", options.Verbose);
                    sql = "SELECT * FROM point_analog_input WHERE oid IN(" + InifyKeys(prPointOids) + ")";
                    da = new NpgsqlDataAdapter(sql, conn);
                    ds.Reset();
                    da.Fill(ds);
                    dt = ds.Tables[0];
                    //copy of points to add
                    rowsToAdd = new List<DataRow>();
                    //get all the address groups and make a copy
                    foreach (DataRow r in dt.Rows)
                    {
                        row = dt.NewRow();
                        row.ItemArray = r.ItemArray.Clone() as object[];
                        row["oid"] = prPointOids[r["oid"] as string];
                        //replace tokens in point names
                        foreach (var kvp in findreplace)
                        {
                            row["entity_name"] = (row["entity_name"] as string).Replace(kvp.Key, kvp.Value);
                        }
                        rowsToAdd.Add(row);
                    }
                    //then insert the copies back into the database
                    foreach (DataRow r in rowsToAdd)
                    {
                        dt.Rows.Add(r);
                    }
                    comb = new NpgsqlCommandBuilder(da);
                    insCommand = comb.GetInsertCommand(true);
                    da.InsertCommand = insCommand;
                    da.Update(ds);
                    PrintVerbose("Done", options.Verbose);
                    //////////////////////////////////////////////////////////////
                    //copy all the analog output points
                    PrintVerbose("Copying AOs...", options.Verbose);
                    sql = "SELECT * FROM point_analog_output WHERE oid IN(" + InifyKeys(prPointOids) + ")";
                    da = new NpgsqlDataAdapter(sql, conn);
                    ds.Reset();
                    da.Fill(ds);
                    dt = ds.Tables[0];
                    //copy of points to add
                    rowsToAdd = new List<DataRow>();
                    //get all the address groups and make a copy
                    foreach (DataRow r in dt.Rows)
                    {
                        row = dt.NewRow();
                        row.ItemArray = r.ItemArray.Clone() as object[];
                        row["oid"] = prPointOids[r["oid"] as string];
                        //replace tokens in point names
                        foreach (var kvp in findreplace)
                        {
                           row["entity_name"] = (row["entity_name"] as string).Replace(kvp.Key, kvp.Value);
                        } 
                        rowsToAdd.Add(row);
                    }
                    //then insert the copies back into the database
                    foreach (DataRow r in rowsToAdd)
                    {
                        dt.Rows.Add(r);
                    }
                    comb = new NpgsqlCommandBuilder(da);
                    insCommand = comb.GetInsertCommand(true);
                    da.InsertCommand = insCommand;
                    da.Update(ds);
                    PrintVerbose("Done", options.Verbose);
                    //////////////////////////////////////////////////////////////
                    //copy all the digital input points
                    PrintVerbose("Copying DIs...", options.Verbose);
                    sql = "SELECT * FROM point_digital_input WHERE oid IN(" + InifyKeys(prPointOids) + ")";
                    da = new NpgsqlDataAdapter(sql, conn);
                    ds.Reset();
                    da.Fill(ds);
                    dt = ds.Tables[0];
                    //copy of points to add
                    rowsToAdd = new List<DataRow>();
                    //get all the address groups and make a copy
                    foreach (DataRow r in dt.Rows)
                    {
                        row = dt.NewRow();
                        row.ItemArray = r.ItemArray.Clone() as object[];
                        row["oid"] = prPointOids[r["oid"] as string];
                        //replace tokens in point names
                        foreach (var kvp in findreplace)
                        {
                           row["entity_name"] = (row["entity_name"] as string).Replace(kvp.Key, kvp.Value);
                        } 
                        rowsToAdd.Add(row);
                    }
                    //then insert the copies back into the database
                    foreach (DataRow r in rowsToAdd)
                    {
                        dt.Rows.Add(r);
                    }
                    comb = new NpgsqlCommandBuilder(da);
                    insCommand = comb.GetInsertCommand(true);
                    da.InsertCommand = insCommand;
                    da.Update(ds);
                    PrintVerbose("Done", options.Verbose);

                    //////////////////////////////////////////////////////////////
                    //copy all the digital output points
                    PrintVerbose("Copying DOs...", options.Verbose);
                    sql = "SELECT * FROM point_digital_output WHERE oid IN(" + InifyKeys(prPointOids) + ")";
                    da = new NpgsqlDataAdapter(sql, conn);
                    ds.Reset();
                    da.Fill(ds);
                    dt = ds.Tables[0];
                    //copy of points to add
                    rowsToAdd = new List<DataRow>();
                    //get all the address groups and make a copy
                    foreach (DataRow r in dt.Rows)
                    {
                        row = dt.NewRow();
                        row.ItemArray = r.ItemArray.Clone() as object[];
                        row["oid"] = prPointOids[r["oid"] as string];
                        //replace tokens in point names
                        foreach (var kvp in findreplace)
                        {
                           row["entity_name"] = (row["entity_name"] as string).Replace(kvp.Key, kvp.Value);
                        }
                        rowsToAdd.Add(row);
                    }
                    //then insert the copies back into the database
                    foreach (DataRow r in rowsToAdd)
                    {
                        dt.Rows.Add(r);
                    }
                    comb = new NpgsqlCommandBuilder(da);
                    insCommand = comb.GetInsertCommand(true);
                    da.InsertCommand = insCommand;
                    da.Update(ds);
                    PrintVerbose("Done", options.Verbose);
                    PrintVerbose("Complete.", options.Verbose);
                }
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write(ex.ToString());
                Console.ForegroundColor = ConsoleColor.White;
            }
        }
        /// <summary>
        /// Recalculates topic and post numbers and updates last post for specified board
        /// </summary>
        /// <param name="boardId">BoardID of board to do re-sync for, if null, all boards are re-synced</param>
        public static void board_resync( object boardId )
        {
            using ( NpgsqlCommand cmd = MsSqlDbAccess.GetCommand( "board_resync" ) )
            {
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.Add(new NpgsqlParameter("i_boardid", NpgsqlDbType.Integer)).Value = boardId;

                NpgsqlCommandBuilder cb = new NpgsqlCommandBuilder();

                MsSqlDbAccess.Current.ExecuteNonQuery(cmd);
            }
        }
Ejemplo n.º 11
0
 public void CommandBuilderQuoting()
 {
     var cb = new NpgsqlCommandBuilder();
     const string orig = "some\"column";
     var quoted = cb.QuoteIdentifier(orig);
     Assert.That(quoted, Is.EqualTo("\"some\"\"column\""));
     Assert.That(cb.UnquoteIdentifier(quoted), Is.EqualTo(orig));
 }
Ejemplo n.º 12
0
        public void Bug1010788UpdateRowSource()
        {
            using (var conn = new NpgsqlConnection(ConnectionString))
            {
                conn.Open();
                ExecuteNonQuery("CREATE TEMP TABLE data (id SERIAL PRIMARY KEY, name TEXT)", conn);
                var command = new NpgsqlCommand("SELECT * FROM data", conn);
                Assert.AreEqual(UpdateRowSource.Both, command.UpdatedRowSource);

                var cmdBuilder = new NpgsqlCommandBuilder();
                var da = new NpgsqlDataAdapter(command);
                cmdBuilder.DataAdapter = da;
                Assert.IsNotNull(da.SelectCommand);
                Assert.IsNotNull(cmdBuilder.DataAdapter);

                NpgsqlCommand updateCommand = cmdBuilder.GetUpdateCommand();
                Assert.AreEqual(UpdateRowSource.None, updateCommand.UpdatedRowSource);
            }
        }
Ejemplo n.º 13
0
        public void Bug1010788UpdateRowSource()
        {
            if (((int)BackendProtocolVersion) < 3)
                Assert.Ignore("Don't have the right metadata with protocol version 2");

            using (var conn = new NpgsqlConnection(ConnectionString))
            {
                conn.Open();
                var command = new NpgsqlCommand("select * from data", conn);
                Assert.AreEqual(UpdateRowSource.Both, command.UpdatedRowSource);

                var cmdBuilder = new NpgsqlCommandBuilder();
                var da = new NpgsqlDataAdapter(command);
                cmdBuilder.DataAdapter = da;
                Assert.IsNotNull(da.SelectCommand);
                Assert.IsNotNull(cmdBuilder.DataAdapter);

                NpgsqlCommand updateCommand = cmdBuilder.GetUpdateCommand();
                Assert.AreEqual(UpdateRowSource.None, updateCommand.UpdatedRowSource);
            }
        }
Ejemplo n.º 14
0
 public void SelectFrom(string what,string from, DataTable dt)
 {
     NpgsqlCommandBuilder myCB = new NpgsqlCommandBuilder();
     NpgsqlDataAdapter myDA = new NpgsqlDataAdapter(String.Format("select {0} from {1}", what, from), postgreConnection);
     try
     {
         myDA.Fill(dt);
     }
     catch (NpgsqlException ex)
     {
         MessageBox.Show(ex.BaseMessage);
     }
 }
Ejemplo n.º 15
0
        public void AutoPopulateAdapterCommands()
        {
            var da = new NpgsqlDataAdapter("SELECT field_pk,field_int4 FROM data", Conn);
            var builder = new NpgsqlCommandBuilder(da);
            var ds = new DataSet();
            da.Fill(ds);

            var table = ds.Tables[0];
            var row = table.NewRow();
            row["field_pk"] = 1;
            row["field_int4"] = 8;
            table.Rows.Add(row);
            da.Update(ds);
            Assert.That(ExecuteScalar(@"SELECT field_int4 FROM data"), Is.EqualTo(8));

            row["field_int4"] = 9;
            da.Update(ds);
            Assert.That(ExecuteScalar(@"SELECT field_int4 FROM data"), Is.EqualTo(9));

            row.Delete();
            da.Update(ds);
            Assert.That(ExecuteScalar(@"SELECT COUNT(*) FROM data"), Is.EqualTo(0));
        }
Ejemplo n.º 16
0
        public void Bug1010788UpdateRowSource()
        {
            using (var conn = new NpgsqlConnection(ConnectionString))
            {
                conn.Open();
                var command = new NpgsqlCommand("select * from data", conn);
                Assert.AreEqual(UpdateRowSource.Both, command.UpdatedRowSource);

                var cmdBuilder = new NpgsqlCommandBuilder();
                var da = new NpgsqlDataAdapter(command);
                cmdBuilder.DataAdapter = da;
                Assert.IsNotNull(da.SelectCommand);
                Assert.IsNotNull(cmdBuilder.DataAdapter);

                NpgsqlCommand updateCommand = cmdBuilder.GetUpdateCommand();
                Assert.AreEqual(UpdateRowSource.None, updateCommand.UpdatedRowSource);
            }
        }
Ejemplo n.º 17
0
        public virtual void DoInsertWithCommandBuilderCaseSensitive()
        {
            var ds = new DataSet();
            var da = new NpgsqlDataAdapter("select * from tablei", Conn);
            var builder = new NpgsqlCommandBuilder(da);
            Assert.IsNotNull(builder);

            da.Fill(ds);

            var dt = ds.Tables[0];
            var dr = dt.NewRow();
            dr["Field_Case_Sensitive"] = 4;
            dt.Rows.Add(dr);

            var ds2 = ds.GetChanges();
            da.Update(ds2);
            ds.Merge(ds2);
            ds.AcceptChanges();

            using (var dr2 = new NpgsqlCommand("select * from tablei", Conn).ExecuteReader())
            {
                dr2.Read();
                Assert.AreEqual(4, dr2[1]);
            }
        }
Ejemplo n.º 18
0
        public virtual void DoUpdateWithDataSet()
        {
            var command = new NpgsqlCommand("insert into tableb(field_int2) values (2)", Conn);
            command.ExecuteNonQuery();

            var ds = new DataSet();
            var da = new NpgsqlDataAdapter("select * from tableb where field_serial = (select max(field_serial) from tableb)", Conn);
            var cb = new NpgsqlCommandBuilder(da);
            Assert.IsNotNull(cb);

            da.Fill(ds);

            var dt = ds.Tables[0];
            Assert.IsNotNull(dt);

            var dr = ds.Tables[0].Rows[ds.Tables[0].Rows.Count - 1];

            dr["field_int2"] = 4;

            var ds2 = ds.GetChanges();
            da.Update(ds2);
            ds.Merge(ds2);
            ds.AcceptChanges();

            using (var dr2 = new NpgsqlCommand("select * from tableb where field_serial = (select max(field_serial) from tableb)", Conn).ExecuteReader())
            {
                dr2.Read();
                Assert.AreEqual(4, dr2["field_int2"]);
            }
        }
Ejemplo n.º 19
0
        public void DataAdapterUpdateReturnValue2()
        {
            var cmd = Conn.CreateCommand();
            var da = new NpgsqlDataAdapter("select * from tabled", Conn);
            var cb = new NpgsqlCommandBuilder(da);
            var ds = new DataSet();
            da.Fill(ds);

            //## Insert a new row with id = 1
            ds.Tables[0].Rows.Add(new Object[] {0.4, 0.5});
            da.Update(ds);

            //## change id from 1 to 2
            cmd.CommandText = "update tabled set field_float4 = 0.8 where id = (select max(field_serial) from tabled)";
            cmd.ExecuteNonQuery();

            //## change value to newvalue
            ds.Tables[0].Rows[0][1] = 0.7;
            //## update should fail, and make a DBConcurrencyException
            var count = da.Update(ds);
            //## count is 1, even if the isn't updated in the database
            Assert.AreEqual(0, count);
        }
Ejemplo n.º 20
0
 public static string QuoteSchemaAndTable(this string sqlQuery, string schemaName, string tableName)
 {
     var cb = new NpgsqlCommandBuilder();
     return string.Format(sqlQuery, cb.QuoteIdentifier(schemaName), cb.QuoteIdentifier(tableName));
 }
Ejemplo n.º 21
-1
    protected void OnExecuteActionActivated(object sender, System.EventArgs e)
    {
        string connectionString = "Server=localhost;Database=dbprueba2;User Id=dbprueba;Password=sistemas;";
        IDbConnection dbConnection = new NpgsqlConnection(connectionString);
        IDbCommand selectCommand = dbConnection.CreateCommand();
        selectCommand.CommandText = "select * from articulos";

        IDbDataAdapter dbDataAdapter = new NpgsqlDataAdapter();
        dbDataAdapter.SelectCommand = selectCommand;

        NpgsqlCommandBuilder commandBuilder = new NpgsqlCommandBuilder((NpgsqlDataAdapter)dbDataAdapter);
        dbConnection.Open();

        DataSet dataSet = new DataSet();

        dbDataAdapter.Fill(dataSet);
        Console.WriteLine("Table.Count={0}\n", dataSet.Tables.Count);

        foreach (DataTable dataTable in dataSet.Tables)
            show (dataTable);

        DataRow dataRow = dataSet.Tables[0].Rows[0];
        dataRow["nombre"] = DateTime.Now.ToString();

        Console.WriteLine ("\nTabla con los cambios:");
        show (dataSet.Tables[0]);

        IDbCommand comando = commandBuilder.GetUpdateCommand (dataSet.Tables[0].Rows[0]);

        //COSAS DE HOY DIA 18

        comando.ExecuteNonQuery ();
    }