public void LoadColorData()
        {
            using (var conn = new GFXDClientConnection(ConnectionString))
            {
                conn.Open();

                // load no data 1=0, but get the columns...
                string query =
                    "select Distinct Color from production.product p" +
                    " join production.productsubcategory ps on ps.ProductSubCategoryID = p.ProductSubCategoryID" +
                    " where ps.name = '" + SubCategorySelected + "' order by Color";
                GFXDCommand cmd = conn.CreateCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = query;

                var da = new GFXDDataAdapter(cmd);
                _dt.Clear();
                // need to add an empty row for deselecting currently selected item.
                _dt.Rows.Add();
                _dt.AcceptChanges();
                //
                da.Fill(_dt);

                LoadColorList();
            }
        }
        public override void Run(Object context)
        {
            int numCommands = 10;
            GFXDCommand[] commands = new GFXDCommand[numCommands];

            try
            {
                int rowCount = DbHelper.GetTableRowCount("Product");

                for (int i = 0; i < numCommands; i++)
                {
                    commands[i] = Connection.CreateCommand();
                    commands[i].CommandText = "SELECT * FROM Product";

                    if (commands[i] == null)
                        Fail("Failed to create GFXDCommand from Connection object.");

                    DataTable dt = new DataTable();
                    GFXDDataAdapter adpt = commands[i].CreateDataAdapter();
                    adpt.Fill(dt);

                    if (dt.Rows.Count != rowCount)
                        Fail("Failed to retrieve all records from table");                    
                }
            }
            catch (Exception e)
            {
                Fail(e);
            }
            finally
            {                
                base.Run(context);
            }
        }
        public void LoadSalesTerritoryData(int key, string value)
        {
            using (var conn = new GFXDClientConnection(ConnectionString))
            {
                conn.Open();

                // load no data 1=0, but get the columns...
                string query;
                if (String.IsNullOrEmpty(value))
                {
                    query = "select TerritoryID, Name from Sales.SalesTerritory order by Name";
                }
                else
                {
                    query = "select TerritoryID, Name from Sales.SalesTerritory where TerritoryID = " +
                            key.ToString() + " order by Name";
                }

                GFXDCommand cmd = conn.CreateCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = query;

                var da = new GFXDDataAdapter(cmd);
                _dt.Clear();
                da.Fill(_dt);

                LoadSalesTerritoryList();
            }
        }
Ejemplo n.º 4
0
        public void DeleteBulkData(string tableName)
        {
            try
            {
                using (var conn = new GFXDClientConnection(ConnectionString))
                {
                    string[] words = tableName.Split('.');

                    GFXDCommand cmd = conn.CreateCommand();
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = "Select MAX(" + words[1] + "ID) from " + tableName;

                    conn.Open();

                    int prodCount = Convert.ToInt32(cmd.ExecuteScalar());

                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = "Delete from " + tableName + " where " + words[1] + "ID between ? and ?";

                    // Insert order_date value and add to command’s Parameters collection
                    GFXDParameter param1 = cmd.CreateParameter();
                    param1.DbType = DbType.Int32;
                    param1.Value  = (prodCount - 1000);
                    cmd.Parameters.Add(param1);
                    // Insert subtotal value add to command’s Parameters collection
                    GFXDParameter param2 = cmd.CreateParameter();
                    param2.DbType = DbType.Int32;
                    param2.Value  = prodCount;
                    cmd.Parameters.Add(param2);

                    var da = new GFXDDataAdapter(cmd);
                    var dt = new DataTable(tableName);
                    da.Fill(dt);



                    //DataTable dt = new DataTable();
                    //var adapter = new GFXDDataAdapter();
                    //cmd.CommandText = "SELECT * FROM Sales.SalesReason";
                    //adapter.SelectCommand = cmd;
                    //DbCommandBuilder builder = new GFXDCommandBuilder(adapter);
                    //adapter.Fill(dt);

                    //for (int i = 500; i < 1000; i++)
                    //{
                    //    dt.Rows[i].Delete();
                    //}

                    //adapter.Update(dt);
                }
            }
            catch (GFXDException ex)
            {
                string err = ex.Message;
            }
            catch (Exception ex)
            {
                string err = ex.Message;
            }
        }
Ejemplo n.º 5
0
        public override void Run(object context)
        {
            GFXDCommand command = null;

            try
            {
                command = Connection.CreateCommand();

                if (command == null)
                {
                    Fail("Command object did not get created");
                }
                if (command.Connection != Connection)
                {
                    Fail(String.Format(
                             "Connection property does not reference the calling "
                             + "Connection object"));
                }
            }
            catch (Exception e)
            {
                Fail(e);
            }
            finally
            {
                base.Run(context);
            }
        }
Ejemplo n.º 6
0
        public static long GetLastRowId(GFXDClientConnection conn, string tableName,
                                        string identityName)
        {
            long id = 0;

            try
            {
                GFXDCommand cmd = conn.CreateCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = String.Format(
                    "SELECT {0} FROM {1} ORDER BY {2} DESC FETCH FIRST 1 ROWS ONLY",
                    identityName, tableName, identityName);

                GFXDDataReader rdr = cmd.ExecuteReader();
                while (rdr.Read())
                {
                    id = long.Parse(rdr.GetString(0));
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e.InnerException);
            }

            return(id);
        }
Ejemplo n.º 7
0
        public static long[] GetAllRowIds(GFXDClientConnection conn,
                                          string tableName, string identityName)
        {
            IList <long> listIds = new List <long>();

            try
            {
                GFXDCommand cmd = conn.CreateCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = String.Format("SELECT {0} FROM {1} ORDER BY {2} ASC",
                                                identityName, tableName, identityName);

                GFXDDataReader rdr = cmd.ExecuteReader();
                while (rdr.Read())
                {
                    listIds.Add(rdr.GetInt64(0));
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e.InnerException);
            }

            return(listIds.ToArray <long>());
        }
Ejemplo n.º 8
0
        public static object Select(GFXDClientConnection connection, string sql, QueryTypes type)
        {
            GFXDCommand command = connection.CreateCommand();

            command.CommandType = System.Data.CommandType.Text;
            command.CommandText = sql;

            if (connection.IsClosed)
            {
                connection.Open();
            }

            if (type == QueryTypes.SCALAR)
            {
                return(command.ExecuteScalar());
            }

            using (GFXDDataAdapter adapter = command.CreateDataAdapter())
            {
                switch (type)
                {
                case QueryTypes.DATAROW: return(GetDataRow(connection, adapter));

                case QueryTypes.DATATABLE: return(GetDataTable(connection, adapter));

                case QueryTypes.DATASET: return(GetDataSet(connection, adapter));

                default: return(null);
                }
            }
        }
Ejemplo n.º 9
0
        public DataSet ExecuteQuery(string query)
        {
            var dt = new DataSet();

            try
            {
                using (var conn = new GFXDClientConnection(ConnectionString))
                {
                    conn.Open();

                    GFXDCommand cmd = conn.CreateCommand();
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = query;

                    var da = new GFXDDataAdapter(cmd);
                    da.Fill(dt);
                }
            }
            catch (GFXDException ex)
            {
                string err = ex.Message;
            }
            catch (Exception ex)
            {
                string err = ex.Message;
            }

            return(dt);
        }
        public override void Run(object context)
        {
            GFXDCommand command;
            String cmdString = "SELECT * FROM " + DbDefault.GetAddressQuery();

            try
            {
                command = new GFXDCommand(cmdString, Connection);

                if (command.CommandText != cmdString)
                    Fail(String.Format(
                        "CommandText property is not initialized with specified "
                        + " command string. Expected {0}; Actual {1}",
                        cmdString, command.CommandText));
                if (command.Connection != Connection)
                    Fail(String.Format(
                        "Connection property is not initialized with the specified "
                        + "GFXDConnection object"));
            }
            catch (Exception e)
            {
                Fail(e);
            }
            finally
            {                
                base.Run(context);
            }
        }
Ejemplo n.º 11
0
        public static long Insert(string sql, bool getId)
        {
            int result = 0;

            using (GFXDClientConnection connection = new GFXDClientConnection(connString))
            {
                ++GFXDTestRunner.ConnCount;

                using (GFXDCommand command = connection.CreateCommand())
                {
                    command.CommandType = System.Data.CommandType.Text;
                    command.CommandText = sql;

                    connection.Open();

                    result = command.ExecuteNonQuery();

                    if (getId)
                    {
                        command.CommandText = "SELECT @@IDENTITY";
                        result = int.Parse(command.ExecuteScalar().ToString());
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 12
0
        public override void Run(object context)
        {
            GFXDCommand command;
            String      cmdString = "SELECT * FROM " + DbDefault.GetAddressQuery();

            try
            {
                command = new GFXDCommand(cmdString, Connection);

                if (command.CommandText != cmdString)
                {
                    Fail(String.Format(
                             "CommandText property is not initialized with specified "
                             + " command string. Expected {0}; Actual {1}",
                             cmdString, command.CommandText));
                }
                if (command.Connection != Connection)
                {
                    Fail(String.Format(
                             "Connection property is not initialized with the specified "
                             + "GFXDConnection object"));
                }
            }
            catch (Exception e)
            {
                Fail(e);
            }
            finally
            {
                base.Run(context);
            }
        }
Ejemplo n.º 13
0
        public static object GetDataField(GFXDClientConnection conn, string tableName,
                                          string fieldName, string identityName, long identityValue)
        {
            if (conn == null)
            {
                return(null);
            }
            if (conn.IsClosed)
            {
                conn.Open();
            }

            object field = new object();

            try
            {
                GFXDCommand cmd = conn.CreateCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = String.Format("SELECT {0} FROM {1} WHERE {2}={3}",
                                                fieldName, tableName, identityName, identityValue);

                field = cmd.ExecuteScalar();
                cmd.Close();
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e.InnerException);
            }

            return(field);
        }
Ejemplo n.º 14
0
        public void ExcuteTransaction(List <string> tables)
        {
            try
            {
                using (var conn = new GFXDClientConnection(ConnectionString))
                {
                    // Open connection, disable auto-commit, and start transaction
                    conn.Open();

                    conn.AutoCommit = false;
                    conn.BeginGFXDTransaction(IsolationLevel.ReadCommitted);
                    GFXDCommand cmd = conn.CreateCommand();
                    cmd.CommandType = CommandType.Text;


                    for (int i = 0; i < tables.Count; i++)
                    {
                        string[] words = tables[i].Split('.');
                        cmd.CommandText = "Select * from " + tables[i] + " order by " + words[1] + "ID";;

                        var adapter = cmd.CreateDataAdapter();
                        var table   = new DataTable(tables[i]);
                        adapter.Fill(table);

                        int cnt = table.Rows.Count;
                        var idx = (int)table.Rows[cnt - 1].ItemArray[0];


                        var builder = new GFXDCommandBuilder(adapter);
                        adapter.InsertCommand = builder.GetInsertCommand();
                        // Create new product row
                        for (int ctx = 0; ctx < 10000; ctx++)
                        {
                            DataRow row = table.NewRow();
                            row[0] = ++idx;
                            for (int j = 1; j < (table.Rows[cnt - 1].ItemArray.Count()); j++)
                            {
                                row[j] = table.Rows[cnt - 1].ItemArray[j];
                            }
                            table.Rows.Add(row);
                        }
                        // Update the underlying table
                        adapter.Update(table);
                    }

                    // Commit transaction
                    conn.Commit();
                }
            }
            catch (GFXDException ex)
            {
                string err = ex.Message;
            }
            catch (Exception ex)
            {
                string err = ex.Message;
            }
        }
Ejemplo n.º 15
0
        public static int ExecuteNonQueryStatement(GFXDClientConnection conn, String statement)
        {
            GFXDCommand cmd = conn.CreateCommand();

            cmd.CommandType = CommandType.Text;
            cmd.CommandText = statement;

            return(cmd.ExecuteNonQuery());
        }
Ejemplo n.º 16
0
        public static object ExecuteScalarStatement(GFXDClientConnection conn, String statement)
        {
            GFXDCommand cmd = conn.CreateCommand();

            cmd.CommandType = CommandType.Text;
            cmd.CommandText = statement;

            return(cmd.ExecuteScalar());
        }
Ejemplo n.º 17
0
        public void GenericCoding()
        {
            // Open a new connection to the network server running on localhost
            string host    = "localhost";
            int    port    = s_clientPort;
            string connStr = string.Format("server={0}:{1}", host, port);

            using (GFXDClientConnection conn = new GFXDClientConnection(connStr)) {
                conn.Open();

                // create a table
                // using the base DbCommand class rather than GemFireXD specific class
                DbCommand cmd = conn.CreateCommand();
                cmd.CommandText = "create table t1 (id int primary key, addr varchar(20))";
                cmd.ExecuteNonQuery();

                try {
                    // insert into the table using named parameters
                    // using an abstracted method that can deal with difference in the
                    // conventions of named parameters in different drivers
                    cmd = conn.CreateCommand();
                    string idPrm   = GetEscapedParameterName("ID");
                    string addrPrm = GetEscapedParameterName("ADDR");
                    cmd.CommandText = "insert into t1 values (" + idPrm + "," + addrPrm + ")";
                    cmd.Prepare();
                    // using the base DbParameter class
                    DbParameter prm;
                    for (int i = 0; i < 1000; i++)
                    {
                        // first the parameter for ID
                        cmd.Parameters.Clear();
                        prm = cmd.CreateParameter();
                        prm.ParameterName = "ID";
                        prm.DbType        = DbType.Int32;
                        prm.Value         = i;
                        cmd.Parameters.Add(prm);
                        // next the parameter for ADDR
                        prm = cmd.CreateParameter();
                        prm.ParameterName = "ADDR";
                        prm.DbType        = DbType.String;
                        prm.Value         = "addr" + i;
                        cmd.Parameters.Add(prm);

                        cmd.ExecuteNonQuery();
                    }

                    // check the inserts
                    VerifyInserts(conn, s_numInserts);
                } finally {
                    // drop the table
                    cmd = new GFXDCommand("drop table t1", conn);
                    cmd.ExecuteNonQuery();

                    conn.Close();
                }
            }
        }
Ejemplo n.º 18
0
        public static DataTable GetDataTable(GFXDClientConnection conn, String statement)
        {
            DataTable       table = new DataTable();
            GFXDCommand     cmd   = new GFXDCommand(statement, conn);
            GFXDDataAdapter adpt  = cmd.CreateDataAdapter();

            adpt.Fill(table);

            return(table);
        }
Ejemplo n.º 19
0
        public void DataAdapterBatch()
        {
            // Open a new connection to the network server running on localhost
            string host    = "localhost";
            int    port    = s_clientPort;
            string connStr = string.Format("server={0}:{1}", host, port);

            using (GFXDClientConnection conn = new GFXDClientConnection(connStr)) {
                conn.Open();

                // create a table
                // using the base DbCommand class rather than GemFireXD specific class
                DbCommand cmd = conn.CreateCommand();
                cmd.CommandText = "create table t1 (id int primary key," +
                                  " addr varchar(20))";
                cmd.ExecuteNonQuery();

                try {
                    // populate DataTable from the underlying table
                    cmd             = conn.CreateCommand();
                    cmd.CommandText = "select * from t1";
                    DbDataAdapter adapter = new GFXDDataAdapter((GFXDCommand)cmd);
                    adapter.SelectCommand = cmd;
                    // associate a command builder with the DataAdapter
                    new GFXDCommandBuilder((GFXDDataAdapter)adapter);
                    // fill a DataTable using the above select SQL command
                    // though there is no data to be populated yet, the schema will still be
                    // set correctly in the DataTable even with no data which is required
                    // before trying to make any updates
                    DataTable table = new DataTable();
                    adapter.Fill(table);
                    // set batch size for best performance
                    adapter.UpdateBatchSize = s_numInserts;
                    // now perform the inserts in the DataTable
                    for (int i = 0; i < s_numInserts; i++)
                    {
                        DataRow newRow = table.NewRow();
                        newRow["ID"]   = i;
                        newRow["ADDR"] = "addr" + i;
                        table.Rows.Add(newRow);
                    }
                    // apply the inserts to the underlying GemFireXD table
                    adapter.Update(table);

                    // check the inserts
                    VerifyInserts(conn, s_numInserts);
                } finally {
                    // drop the table
                    cmd = new GFXDCommand("drop table t1", conn);
                    cmd.ExecuteNonQuery();

                    conn.Close();
                }
            }
        }
Ejemplo n.º 20
0
        /// <summary>
        /// check for various connection attributes in addition to auth
        /// (examples from reference guide)
        /// </summary>
        public void BasicAuthentication()
        {
            // First use the connection with system user to create a new user.
            string host    = "localhost";
            int    port    = s_clientPort;
            string user    = "******";
            string passwd  = "gemfire1";
            string connStr = string.Format("server={0}:{1};user={2};password={3}",
                                           host, port, user, passwd);

            using (GFXDClientConnection conn = new GFXDClientConnection(connStr)) {
                conn.Open();
                // fire a simple query to check the connection
                GFXDCommand cmd = conn.CreateCommand();
                cmd.CommandText = "select count(*) from sys.members";
                Assert.AreEqual(1, cmd.ExecuteScalar());
                // create new user
                cmd.CommandText = "call sys.create_user('gemfirexd.user.gem2', 'gem2')";
                Assert.AreEqual(-1, cmd.ExecuteNonQuery());
                conn.Close();
            }

            // Open a new connection to the locator having network server
            // with username and password in the connection string.
            user    = "******";
            passwd  = "gem2";
            connStr = string.Format("server={0}:{1};user={2};password={3}",
                                    host, port, user, passwd);
            using (GFXDClientConnection conn = new GFXDClientConnection(connStr)) {
                conn.Open();
                // fire a simple query to check the connection
                GFXDCommand cmd = conn.CreateCommand();
                cmd.CommandText = "select count(*) from sys.members";
                Assert.AreEqual(1, cmd.ExecuteScalar());
                conn.Close();
            }

            // Open a new connection to the locator having network server
            // with username and password passed as properties.
            connStr = string.Format("server={0}:{1}", host, port);
            using (GFXDClientConnection conn = new GFXDClientConnection(connStr)) {
                Dictionary <string, string> props = new Dictionary <string, string>();
                props.Add("user", user);
                props.Add("password", passwd);
                props.Add("disable-streaming", "true");
                props.Add("load-balance", "false");
                conn.Open(props);
                // fire a simple query to check the connection
                GFXDCommand cmd = conn.CreateCommand();
                cmd.CommandText = "select count(*) from sys.members";
                Assert.AreEqual(1, cmd.ExecuteScalar());
                conn.Close();
            }
        }
Ejemplo n.º 21
0
        public void CopyToParameterCollection()
        {
            DbCommand cmd = m_conn.CreateCommand();

            cmd.CommandText = "SELECT fname FROM employee WHERE fname=:fname" +
                              " AND lname=?";
            DbParameter p1Fname;
            DbParameter p1Lname;

            if (cmd is GFXDCommand)
            {
                GFXDCommand scmd = (GFXDCommand)cmd;
                p1Fname = scmd.Parameters.Add("fname", GFXDType.VarChar, 15);
            }
            else
            {
                p1Fname = cmd.CreateParameter();
                p1Fname.ParameterName = "fname";
                p1Fname.DbType        = DbType.AnsiString;
                p1Fname.Value         = 15;
                cmd.Parameters.Add(p1Fname);
            }
            p1Lname        = cmd.CreateParameter();
            p1Lname.DbType = DbType.String;
            p1Lname.Value  = 15;
            cmd.Parameters.Add(p1Lname);

            Assert.AreEqual(2, cmd.Parameters.Count, "#1 Initialization error," +
                            " parameter collection must contain 2 elements");
            Assert.AreSame(p1Fname, cmd.Parameters["fname"], "#2 Should find the" +
                           " same parameter as that added");
            Assert.AreSame(p1Fname, cmd.Parameters[0], "#3 Should find the" +
                           " same parameter as that added");
            Assert.AreSame(p1Lname, cmd.Parameters[1], "#4 Should find the" +
                           " same parameter as that added");
            Assert.IsNull(cmd.Parameters["lname"], "#5 Expected to find a null" +
                          " parameter for non-existing name");

            DbParameter[] destinationArray = new DbParameter[4];
            cmd.Parameters.CopyTo(destinationArray, 1);
            Assert.AreEqual(4, destinationArray.Length, "#6 The length of" +
                            " destination array should not change");
            Assert.AreEqual(null, destinationArray[0], "#7 The parameter collection" +
                            " is copied at index 1, so the first element should not change");
            Assert.AreEqual(p1Fname, destinationArray[1], "#8 The parameter" +
                            " at index 1 must be p1Fname");
            Assert.AreEqual(p1Lname, destinationArray[2], "#9 The parameter" +
                            " at index 2 must be p1Lname");
            Assert.AreEqual(null, destinationArray[3], "#10 The parameter" +
                            " at index 3 must not change");
        }
Ejemplo n.º 22
0
        public static int Drop(GFXDClientConnection connection, string sql)
        {
            GFXDCommand command = connection.CreateCommand();

            command.CommandType = System.Data.CommandType.Text;
            command.CommandText = sql;

            if (connection.IsClosed)
            {
                connection.Open();
            }

            return(command.ExecuteNonQuery());
        }
Ejemplo n.º 23
0
        public void NamedParameters()
        {
            // Open a new connection to the network server running on localhost
            string host    = "localhost";
            int    port    = s_clientPort;
            string connStr = string.Format("server={0}:{1}", host, port);

            using (GFXDClientConnection conn = new GFXDClientConnection(connStr)) {
                conn.Open();

                // create a table
                GFXDCommand cmd = new GFXDCommand("create table t1 (id int primary" +
                                                  " key, addr varchar(20))", conn);
                cmd.ExecuteNonQuery();

                try {
                    // insert into the table using named parameters
                    cmd = new GFXDCommand("insert into t1 values (:ID, :ADDR)", conn);
                    cmd.Prepare();
                    DbParameter prm;
                    for (int i = 0; i < s_numInserts; i++)
                    {
                        // first the parameter for ID
                        cmd.Parameters.Clear();
                        prm = cmd.CreateParameter();
                        prm.ParameterName = "ID";
                        prm.DbType        = DbType.Int32;
                        prm.Value         = i;
                        cmd.Parameters.Add(prm);
                        // then the parameter for ADDR
                        prm = cmd.CreateParameter();
                        prm.ParameterName = "ADDR";
                        prm.DbType        = DbType.String;
                        prm.Value         = "addr" + i;
                        cmd.Parameters.Add(prm);

                        cmd.ExecuteNonQuery();
                    }

                    // check the inserts
                    VerifyInserts(conn, s_numInserts);
                } finally {
                    // drop the table
                    cmd = new GFXDCommand("drop table t1", conn);
                    cmd.ExecuteNonQuery();

                    conn.Close();
                }
            }
        }
Ejemplo n.º 24
0
        public static DataTable SelectRandom(GFXDClientConnection connection, TableName tableName, int numRows)
        {
            GFXDCommand command = connection.CreateCommand();

            command.CommandType = System.Data.CommandType.Text;
            command.CommandText = String.Format(
                "SELECT * FROM {0} ORDER BY RANDOM() FETCH FIRST {1} ROWS ONLY",
                tableName.ToString(), numRows);

            using (GFXDDataAdapter adapter = command.CreateDataAdapter())
            {
                return(GetDataTable(connection, adapter));
            }
        }
Ejemplo n.º 25
0
        public void InsertBulkData(string tableName)
        {
            try
            {
                using (var conn = new GFXDClientConnection(ConnectionString))
                {
                    string[]    words = tableName.Split('.');
                    GFXDCommand cmd   = conn.CreateCommand();
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = "Select * from " + tableName + " order by " + words[1] + "ID";

                    conn.Open();


                    GFXDDataAdapter adapter = cmd.CreateDataAdapter();
                    var             table   = new DataTable(tableName);
                    adapter.Fill(table);


                    int cnt = table.Rows.Count;
                    var idx = (int)table.Rows[cnt - 1].ItemArray[0];


                    var builder = new GFXDCommandBuilder(adapter);
                    adapter.InsertCommand = builder.GetInsertCommand();
                    // Create new product row
                    for (int ctx = 0; ctx < 10000; ctx++)
                    {
                        DataRow row = table.NewRow();
                        row[0] = ++idx;
                        for (int i = 1; i < (table.Rows[cnt - 1].ItemArray.Count()); i++)
                        {
                            row[i] = table.Rows[cnt - 1].ItemArray[i];
                        }
                        table.Rows.Add(row);
                    }
                    // Update the underlying table
                    adapter.Update(table);
                }
            }
            catch (GFXDException ex)
            {
                string err = ex.Message;
            }
            catch (Exception ex)
            {
                string err = ex.Message;
            }
        }
Ejemplo n.º 26
0
        public static int Drop(string sql)
        {
            using (GFXDClientConnection connection = new GFXDClientConnection(connString))
            {
                using (GFXDCommand command = connection.CreateCommand())
                {
                    command.CommandType = System.Data.CommandType.Text;
                    command.CommandText = sql;

                    connection.Open();

                    return(command.ExecuteNonQuery());
                }
            }
        }
Ejemplo n.º 27
0
        public static void InsertTable(String schemaName, String tableName, int numRows)
        {
            GFXDClientConnection conn   = DbHelper.OpenNewConnection();
            GFXDCommand          cmd    = conn.CreateCommand();
            String        tableFullName = String.Format("{0}.{1}", schemaName, tableName);
            StringBuilder sql           = new StringBuilder();
            long          startId       = startPKeyId;

            sql.AppendFormat("INSERT INTO {0} (", tableFullName);
            foreach (DbField field in randomTable.Columns)
            {
                sql.AppendFormat("{0}, ", field.FieldName);
            }

            sql = sql.Remove(sql.Length - 2, 1).Append(") ");
            sql.Append("VALUES (");

            foreach (DbField field in randomTable.Columns)
            {
                sql.Append("?, ");
            }

            sql             = sql.Remove(sql.Length - 2, 1).Append(") ");
            cmd.CommandText = sql.ToString();
            cmd.Prepare();

            DbHelper.Log(cmd.CommandText);

            int batchCount = 0;

            for (int i = 0; i < numRows; i++)
            {
                foreach (DbField field in randomTable.Columns)
                {
                    cmd.Parameters.Add(GetRandomFieldData(field));
                }
                cmd.Parameters[0] = startId++;

                cmd.AddBatch();

                if ((++batchCount) == batchSize)
                {
                    cmd.ExecuteBatch();
                    batchCount = 0;
                }
            }
            cmd.ExecuteBatch();
        }
Ejemplo n.º 28
0
        public void PositionalParametersBatch()
        {
            // Open a new connection to the network server running on localhost
            string host    = "localhost";
            int    port    = s_clientPort;
            string connStr = string.Format("server={0}:{1}", host, port);

            using (GFXDClientConnection conn = new GFXDClientConnection(connStr)) {
                conn.Open();

                // create a table
                GFXDCommand cmd = new GFXDCommand("create table t1 (id int primary" +
                                                  " key, addr varchar(20))", conn);
                cmd.ExecuteNonQuery();

                try {
                    // insert into the table using positional parameters
                    cmd = new GFXDCommand("insert into t1 values (?, ?)", conn);
                    cmd.Prepare();
                    for (int i = 0; i < s_numInserts; i++)
                    {
                        cmd.Parameters.Add(i);
                        cmd.Parameters.Add("addr" + i);
                        cmd.AddBatch();
                    }
                    int[] results = cmd.ExecuteBatch();

                    // check the inserts
                    Assert.AreEqual(s_numInserts, results.Length);
                    for (int i = 0; i < s_numInserts; i++)
                    {
                        Assert.AreEqual(1, results[i], "unexpected result=" + results[i] +
                                        " for i=" + i);
                    }
                    // also check in the database
                    VerifyInserts(conn, s_numInserts);
                } finally {
                    // drop the table
                    cmd = new GFXDCommand("drop table t1", conn);
                    cmd.ExecuteNonQuery();

                    conn.Close();
                }
            }
        }
Ejemplo n.º 29
0
        public static long GetRandomRowId(GFXDClientConnection conn, string tableName,
                                          string identityName)
        {
            try
            {
                GFXDCommand cmd = conn.CreateCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = String.Format(
                    "SELECT {0} FROM {1} ORDER BY RANDOM() FETCH FIRST 1 ROWS ONLY",
                    identityName, tableName);

                return(Convert.ToInt64(cmd.ExecuteScalar()));
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e.InnerException);
            }
        }
Ejemplo n.º 30
0
        public void LoadTableRowListData(string table)
        {
            using (GFXDClientConnection conn = new GFXDClientConnection(ConnectionString))
            {
                conn.Open();

                // load no data 1=0, but get the columns...
                string query =
                    "SELECT * FROM " + table;
                GFXDCommand cmd = conn.CreateCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = query;

                GFXDDataAdapter da = new GFXDDataAdapter(cmd);
                _dtTableDataRows.Clear();
                da.Fill(_dtTableDataRows);
            }
        }
Ejemplo n.º 31
0
        public DataSet ExecuteQuery(string query)
        {
            // comment this line if only non-connection pooling test desired
            connectionStr += ";userID=syed;password=syed;MinimumPoolSize=1;MaximumPoolSize=5;ConnectionLifetime=60;Pooling=true";


            var dt = new DataSet();

            try
            {
                var conn = new GFXDClientConnection(connectionStr);
                for (int i = 0; i < 1000; i++)
                {
                    conn.Open();
                    GFXDCommand cmd = conn.CreateCommand();
                    //cmd.CommandType = CommandType.Text;

                    cmd.CommandText = query;



                    //for (int i = 0; i < 1; i++)
                    //{
                    cmd.ExecuteNonQuery();
                    //}


                    //var da = new GFXDDataAdapter(cmd);
                    //da.Fill(dt);

                    conn.Close();
                }
            }
            catch (GFXDException ex)
            {
                string err = ex.Message;
            }
            catch (Exception ex)
            {
                string err = ex.Message;
            }

            return(dt);
        }
Ejemplo n.º 32
0
        public void UpdateBulkData(string tableName)
        {
            try
            {
                using (var conn = new GFXDClientConnection(ConnectionString))
                {
                    conn.Open();

                    //GFXDCommand cmd = conn.CreateCommand();
                    //cmd.CommandType = CommandType.Text;
                    //cmd.CommandText = "Delete from Sales.SalesReason where SalesReasonID between 17000 and 19485";

                    //var da = new GFXDDataAdapter(cmd);
                    //var dt = new DataTable();
                    //da.Fill(dt);


                    GFXDCommand cmd = conn.CreateCommand();

                    DataTable dt      = new DataTable();
                    var       adapter = new GFXDDataAdapter();
                    cmd.CommandText       = "SELECT * FROM Sales.SalesReason";
                    adapter.SelectCommand = cmd;
                    DbCommandBuilder builder = new GFXDCommandBuilder(adapter);
                    adapter.Fill(dt);

                    for (int i = 500; i < 1000; i++)
                    {
                        dt.Rows[i].Delete();
                    }

                    adapter.Update(dt);
                }
            }
            catch (GFXDException ex)
            {
                string err = ex.Message;
            }
            catch (Exception ex)
            {
                string err = ex.Message;
            }
        }
Ejemplo n.º 33
0
 protected void VerifyInserts(GFXDConnection conn, string cmdText,
                              int start, int end, string addrPrefix)
 {
   // check the inserts
   GFXDCommand cmd = new GFXDCommand(cmdText, conn);
   Dictionary<int, string> result =
     new Dictionary<int, string>(end - start + 1);
   int id;
   string addr;
   GFXDDataReader reader = cmd.ExecuteReader();
   for (int i = start; i <= end; i++) {
     Assert.IsTrue(reader.Read(), "failed in read for i=" + i);
     id = reader.GetInt32(0);
     addr = reader.GetString(1);
     Assert.IsFalse(result.ContainsKey(id),
                    "unexpected duplicate for id=" + id);
     Assert.AreEqual(addrPrefix + id, addr);
     result.Add(id, addr);
   }
   Assert.IsFalse(reader.Read());
 }
Ejemplo n.º 34
0
    public void MixedParameters()
    {
      // Open a new connection to the network server running on localhost
      string host = "localhost";
      int port = s_clientPort;
      string connStr = string.Format("server={0}:{1}", host, port);
      using (GFXDClientConnection conn = new GFXDClientConnection(connStr)) {
        conn.Open();

        // create a table
        GFXDCommand cmd = new GFXDCommand("create table t1 (id int primary" +
                                          " key, addr varchar(20))", conn);
        cmd.ExecuteNonQuery();

        try {
          // insert into the table using named parameters
          cmd = new GFXDCommand("insert into t1 values (:ID, ?)", conn);
          cmd.Prepare();
          DbParameter prm;
          for (int i = 0; i < s_numInserts; i++) {
            // first the parameter for ID
            cmd.Parameters.Clear();
            prm = cmd.CreateParameter();
            prm.ParameterName = "ID";
            prm.DbType = DbType.Int32;
            prm.Value = i;
            cmd.Parameters.Add(prm);
            // then the parameter for ADDR
            prm = cmd.CreateParameter();
            prm.ParameterName = "ADDR";
            prm.Value = "addr" + i;
            cmd.Parameters.Add(prm);

            cmd.ExecuteNonQuery();
          }

          // check the inserts
          VerifyInserts(conn, s_numInserts);

        } finally {
          // drop the table
          cmd = new GFXDCommand("drop table t1", conn);
          cmd.ExecuteNonQuery();

          conn.Close();
        }
      }
    }
        public override void Run(object context)
        {
            int dsSize = 10;
            DataSet dataset = new DataSet();
            String[] tableNames = new String[dsSize];
            GFXDCommand[] commands = new GFXDCommand[dsSize];
            GFXDDataAdapter[] adapters = new GFXDDataAdapter[dsSize];

            try
            {
                for (int i = 0; i < dsSize; i++)
                {
                    tableNames[i] = DbRandom.BuildRandomTable(5);
                    commands[i] = Connection.CreateCommand();
                    commands[i].CommandText = String.Format(
                        "SELECT * FROM {0} ORDER BY COL_ID ASC ", tableNames[i]);

                    adapters[i] = commands[i].CreateDataAdapter();
                    adapters[i].Fill(dataset, tableNames[i]);                    
                }

                ParseDataSet(dataset);

                IList<object> data = DbRandom.GetRandomRowData();

                for (int i = 0; i < dsSize; i++)
                {
                    CommandBuilder = new GFXDCommandBuilder(adapters[i]);

                    for (int j = 0; j < dataset.Tables[tableNames[i]].Rows.Count; j++)
                        for (int k = 1; k < dataset.Tables[tableNames[i]].Columns.Count; k++) // do not update identity column
                            dataset.Tables[tableNames[i]].Rows[j][k] = data[k];

                    if (adapters[i].Update(dataset, tableNames[i])
                        != dataset.Tables[tableNames[i]].Rows.Count)
                        Fail(String.Format(
                            "Failed to update all changed rows in table {0}", tableNames[i]));
                }

                dataset.Clear();

                for (int i = 0; i < dsSize; i++)
                    adapters[i].Fill(dataset, tableNames[i]);

                ParseDataSet(dataset);

                foreach (DataTable table in dataset.Tables)
                {
                    foreach (DataRow row in table.Rows)
                    {
                        for (int i = 1; i < row.Table.Columns.Count; i++)
                        {
                            if (!DbRandom.Compare(data[i], row, i))
                            {
                                Fail(String.Format(
                                    "Inconsistent updated data in table [{0}] at row [{1}] column [{2}]. "
                                    + "Expected [{3}]; Actual [{4}]",
                                    table.TableName,
                                    row[0].ToString(), row.Table.Columns[i].ColumnName,
                                    data[i].ToString(), row[i].ToString()));
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {                
                Fail(e);
            }
            finally
            {
                try
                {
                    foreach(String tableName in tableNames)
                        DbRandom.DropTable(tableName);
                }
                catch (Exception e)
                {
                    Fail(e);
                }

                base.Run(context);
            }
        }
Ejemplo n.º 36
0
    public void OverloadedConstructorsTest()
    {
      DbCommand selCmd = m_conn.CreateCommand();
      selCmd.CommandText = "Select * from numeric_family";
      m_adapter = GetDataAdapter();
      m_adapter.SelectCommand = selCmd;
      Assert.AreEqual(MissingMappingAction.Passthrough,
                      m_adapter.MissingMappingAction,
                      "#1 Missing Mapping action default to Passthrough");
      Assert.AreEqual(MissingSchemaAction.Add, m_adapter.MissingSchemaAction,
                      "#2 Missing Schme action default to Add");
      Assert.AreSame(selCmd, m_adapter.SelectCommand,
                     "#3 Select Command shud be a ref to the arg passed");

      DbConnection conn = OpenNewConnection();
      if (conn is GFXDConnection) {
        GFXDConnection gfxdConn = (GFXDConnection)conn;
        String selStr = "Select * from numeric_family";
        m_adapter = new GFXDDataAdapter(selStr, gfxdConn);
        Assert.AreEqual(MissingMappingAction.Passthrough,
                        m_adapter.MissingMappingAction,
                        "#4 Missing Mapping action default to Passthrough");
        Assert.AreEqual(MissingSchemaAction.Add, m_adapter.MissingSchemaAction,
                        "#5 Missing Schme action default to Add");
        Assert.AreSame(selStr, m_adapter.SelectCommand.CommandText,
                       "#6 Select Command shud be a ref to the arg passed");
        Assert.AreSame(conn, m_adapter.SelectCommand.Connection,
                       "#7 cmd.connection shud be t ref to connection obj");

        GFXDCommand selCommand = new GFXDCommand(selStr, gfxdConn);
        m_adapter = new GFXDDataAdapter(selCommand);
        Assert.AreEqual(MissingMappingAction.Passthrough,
                        m_adapter.MissingMappingAction,
                        "#8 Missing Mapping action default to Passthrough");
        Assert.AreEqual(MissingSchemaAction.Add, m_adapter.MissingSchemaAction,
                        "#9 Missing Schema action shud default to Add");
        Assert.AreSame(selCommand, m_adapter.SelectCommand, "#10");
        Assert.AreSame(selStr, m_adapter.SelectCommand.CommandText, "#11");
        Assert.AreSame(gfxdConn, m_adapter.SelectCommand.Connection, "#12");
      }
      conn.Close();
    }
        public override void Run(object context)
        {
            GFXDCommand command;
            String cmdString = "SELECT * FROM " + DbDefault.GetAddressQuery();

            try
            {
                command = new GFXDCommand(cmdString, Connection);

                if (command.CommandText != cmdString)
                {
                    Fail(String.Format(
                        "CommandText property is not initialized with specified "
                        + " command string. Expected {0}; Actual {1}",
                        cmdString, command.CommandText));
                }
                if (command.Connection != Connection)
                {
                    Fail(String.Format(
                        "Connection property is not initialized with the specified "
                        + "GFXDConnection object"));
                }
                if (command.CommandTimeout != -1)
                {
                    Fail(String.Format(
                        "CommandTimeout default setting is incorrect. "
                        + "Expected [{0}]; Actual [{1}]",
                        -1, command.CommandTimeout));
                }
                if (command.CommandType != System.Data.CommandType.Text)
                {
                    Fail(String.Format(
                        "CommandType default setting is incorrect. "
                        + "Expected [{0}]; Actual [{1}]",
                        System.Data.CommandType.Text, command.CommandType));
                }
                if (command.FetchSize != 0)
                {
                    Fail(String.Format(
                        "FetchSize default setting is incorrect. "
                        + "Expected [{0}]; Actual [{1}]",
                        0, command.FetchSize));
                }
                // CHANGED if (command.ReaderHoldOverCommit != false)
                //{
                //    Fail(String.Format(
                //        "ReaderHoldOverCommit default setting is incorrect. "
                //        + "Expected [{0}]; Actual [{1}]",
                //        false, command.ReaderHoldOverCommit));
                //}
                if (command.ReaderType != GFXDCommand.DataReaderType.ForwardOnly)
                {
                    Fail(String.Format(
                        "ReaderType default setting is incorrect. "
                        + "Expected [{0}]; Actual [{1}]",
                        GFXDCommand.DataReaderType.ForwardOnly, command.ReaderType));
                }
                // CHANGED if (command.ReaderUpdatable != false)
                //{
                //    Fail(String.Format(
                //        "ReaderUpdatable default setting is incorrect. "
                //        + "Expected [{0}]; Actual [{1}]",
                //        false, command.ReaderUpdatable));
                //}
            }
            catch (Exception e)
            {
                Fail(e);
            }
            finally
            {                
                base.Run(context);
            }
        }
        public override void Run(object context)
        {
            int updateSize = 5;
            DataTable[] tables = new DataTable[updateSize];
            String[] tableNames = new String[updateSize];
            GFXDClientConnection[] conns = new GFXDClientConnection[updateSize];
            GFXDCommand[] cmds = new GFXDCommand[updateSize];
            GFXDDataAdapter[] adpts = new GFXDDataAdapter[updateSize];

            try
            {
                for (int i = 0; i < updateSize; i++)
                {
                    tableNames[i] = DbRandom.BuildRandomTable(5);
                    conns[i] = new GFXDClientConnection(ConnectionString);
                    cmds[i] = conns[i].CreateCommand();
                    cmds[i].CommandText = String.Format(
                        "SELECT * FROM {0} ORDER BY COL_ID ASC ", tableNames[i]);

                    conns[i].Open();
                    conns[i].AutoCommit = false;
                    conns[i].BeginGFXDTransaction();

                    adpts[i] = cmds[i].CreateDataAdapter();
                    tables[i] = new DataTable();
                    adpts[i].Fill(tables[i]);
                    ParseDataTable(tables[i]);
                }

                IList<object> data = DbRandom.GetRandomRowData();

                for (int i = 0; i < updateSize; i++)
                {
                    CommandBuilder = new GFXDCommandBuilder(adpts[i]);

                    for (int j = 0; j < tables[i].Rows.Count; j++)
                        for (int k = 1; k < tables[i].Columns.Count; k++)
                            tables[i].Rows[j][k] = data[k];

                    if (adpts[i].Update(tables[i]) != tables[i].Rows.Count)
                        Fail(String.Format(
                            "Failed to update table {0}", tableNames[i]));

                    try
                    {
                        conns[i].Commit();
                    }
                    catch (Exception e)
                    {
                        conns[i].Rollback();
                        Fail(e);
                    }
                }

                for (int i = 0; i < updateSize; i++)
                {
                    tables[i].Clear();
                    adpts[i].Fill(tables[i]);             
                }

                foreach (DataTable table in tables)
                {
                    foreach (DataRow row in table.Rows)
                    {
                        for (int i = 1; i < row.Table.Columns.Count; i++)
                        {
                            if (!DbRandom.Compare(data[i], row, i))
                            {
                                Fail(String.Format(
                                    "Inconsistent updated data in table [{0}] at row [{1}] column [{2}]. "
                                    + "Expected [{3}]; Actual [{4}]",
                                    table.TableName,
                                    row[0].ToString(), row.Table.Columns[i].ColumnName,
                                    data[i].ToString(), row[i].ToString()));
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Fail(e);
            }
            finally
            {
                foreach (String tableName in tableNames)
                    DbRandom.DropTable(tableName);

                base.Run(context);
            }
        }
Ejemplo n.º 39
0
    public void GenericCoding()
    {
      // Open a new connection to the network server running on localhost
      string host = "localhost";
      int port = s_clientPort;
      string connStr = string.Format("server={0}:{1}", host, port);
      using (GFXDClientConnection conn = new GFXDClientConnection(connStr)) {
        conn.Open();

        // create a table
        // using the base DbCommand class rather than GemFireXD specific class
        DbCommand cmd = conn.CreateCommand();
        cmd.CommandText = "create table t1 (id int primary key, addr varchar(20))";
        cmd.ExecuteNonQuery();

        try {
          // insert into the table using named parameters
          // using an abstracted method that can deal with difference in the
          // conventions of named parameters in different drivers
          cmd = conn.CreateCommand();
          string idPrm = GetEscapedParameterName("ID");
          string addrPrm = GetEscapedParameterName("ADDR");
          cmd.CommandText = "insert into t1 values (" + idPrm + "," + addrPrm + ")";
          cmd.Prepare();
          // using the base DbParameter class
          DbParameter prm;
          for (int i = 0; i < 1000; i++) {
            // first the parameter for ID
            cmd.Parameters.Clear();
            prm = cmd.CreateParameter();
            prm.ParameterName = "ID";
            prm.DbType = DbType.Int32;
            prm.Value = i;
            cmd.Parameters.Add(prm);
            // next the parameter for ADDR
            prm = cmd.CreateParameter();
            prm.ParameterName = "ADDR";
            prm.DbType = DbType.String;
            prm.Value = "addr" + i;
            cmd.Parameters.Add(prm);

            cmd.ExecuteNonQuery();
          }

          // check the inserts
          VerifyInserts(conn, s_numInserts);

        } finally {
          // drop the table
          cmd = new GFXDCommand("drop table t1", conn);
          cmd.ExecuteNonQuery();

          conn.Close();
        }
      }
    }
Ejemplo n.º 40
0
    public void TransactionTest()
    {
      // Open a new connection to the network server running on localhost
      string host = "localhost";
      int port = s_clientPort;
      string connStr = string.Format("server={0}:{1}", host, port);
      using (GFXDClientConnection conn = new GFXDClientConnection(connStr)) {
        conn.Open();

        // create a table
        GFXDCommand cmd = new GFXDCommand("create table t1 (id int primary" +
                                          " key, addr varchar(20))", conn);
        cmd.ExecuteNonQuery();

        try {
          GFXDTransaction tran = conn.BeginTransaction(IsolationLevel
                                                       .ReadCommitted);
          cmd.Transaction = tran;
          // insert into the table using positional parameters
          cmd = new GFXDCommand("insert into t1 (id, addr) values (?, ?)",
                                conn);
          cmd.Prepare();
          for (int i = 0; i < s_numInserts; i++) {
            cmd.Parameters.Clear();
            cmd.Parameters.Add(i);
            cmd.Parameters.Add("addr" + i);

            cmd.ExecuteNonQuery();
          }
          tran.Commit();

          // check the inserts
          VerifyInserts(conn, s_numInserts);

          // fire some updates and if any unsuccessful then rollback the transaction
          cmd.CommandText = "update t1 set addr = ? where id = ?";
          tran = conn.BeginTransaction(IsolationLevel.ReadCommitted);
          cmd.Transaction = tran;
          bool success = true;
          for (int i = 100; i < 200; i++) {
            cmd.Parameters.Clear();
            cmd.Parameters.Add("address" + i);
            cmd.Parameters.Add(i);
            if (cmd.ExecuteNonQuery() != 1) {
              // update failed; rolling back the entire transaction
              success = false;
              tran.Rollback();
              break;
            }
          }
          // command for verification
          string verifyText = "select * from t1 where id >= 100 and id < 200";
          if (success) {
            // verify the updates in transactional data
            VerifyInserts(conn, verifyText, 100, 199, "address");
            // all succeeded; commit the transaction
            tran.Commit();
            // verify the updates after commit
            VerifyInserts(conn, verifyText, 100, 199, "address");
          }
          else {
            // verify no updates
            VerifyInserts(conn, verifyText, 100, 199, "addr");
          }

        } finally {
          // drop the table
          cmd = new GFXDCommand("drop table t1", conn);
          cmd.ExecuteNonQuery();

          conn.Close();
        }
      }
    }
Ejemplo n.º 41
0
    public void DataReaderWithPositionalParameters()
    {
      // Open a new connection to the network server running on localhost
      string host = "localhost";
      int port = s_clientPort;
      string connStr = string.Format("server={0}:{1}", host, port);
      using (GFXDClientConnection conn = new GFXDClientConnection(connStr)) {
        conn.Open();

        // create a table
        GFXDCommand cmd = new GFXDCommand("create table t1 (id int primary" +
                                          " key, addr varchar(20))", conn);
        cmd.ExecuteNonQuery();

        try {
          // insert into the table using positional parameters
          cmd = new GFXDCommand("insert into t1 (id, addr) values (?, ?)",
                                conn);
          cmd.Prepare();
          for (int i = 1; i <= s_numInserts; i++) {
            cmd.Parameters.Clear();
            cmd.Parameters.Add(i);
            cmd.Parameters.Add("addr" + i);

            cmd.ExecuteNonQuery();
          }

          // now query the table using a DataReader
          cmd.Parameters.Clear();
          cmd.CommandText = "select * from t1";
          GFXDDataReader reader = cmd.ExecuteReader();
          int[] ids = new int[s_numInserts];
          int numResults = 0;
          while (reader.Read()) {
            int id = reader.GetInt32(0);
            string addr = reader.GetString(1);
            if (ids[id - 1] != 0) {
              throw new Exception("Duplicate value for ID=" + id +
                                  " addr=" + addr);
            }
            ids[id - 1] = id;
            numResults++;
          }
          reader.Close();
          if (numResults != s_numInserts) {
            throw new Exception("unexpected number of results " + numResults);
          }

        } finally {
          // drop the table
          cmd = new GFXDCommand("drop table t1", conn);
          cmd.ExecuteNonQuery();

          conn.Close();
        }
      }
    }
Ejemplo n.º 42
0
    public void DataAdapterBatch()
    {
      // Open a new connection to the network server running on localhost
      string host = "localhost";
      int port = s_clientPort;
      string connStr = string.Format("server={0}:{1}", host, port);
      using (GFXDClientConnection conn = new GFXDClientConnection(connStr)) {
        conn.Open();

        // create a table
        // using the base DbCommand class rather than GemFireXD specific class
        DbCommand cmd = conn.CreateCommand();
        cmd.CommandText = "create table t1 (id int primary key," +
          " addr varchar(20))";
        cmd.ExecuteNonQuery();

        try {
          // populate DataTable from the underlying table
          cmd = conn.CreateCommand();
          cmd.CommandText = "select * from t1";
          DbDataAdapter adapter = new GFXDDataAdapter((GFXDCommand)cmd);
          adapter.SelectCommand = cmd;
          // associate a command builder with the DataAdapter
          new GFXDCommandBuilder((GFXDDataAdapter)adapter);
          // fill a DataTable using the above select SQL command
          // though there is no data to be populated yet, the schema will still be
          // set correctly in the DataTable even with no data which is required
          // before trying to make any updates
          DataTable table = new DataTable();
          adapter.Fill(table);
          // set batch size for best performance
          adapter.UpdateBatchSize = s_numInserts;
          // now perform the inserts in the DataTable
          for (int i = 0; i < s_numInserts; i++) {
            DataRow newRow = table.NewRow();
            newRow["ID"] = i;
            newRow["ADDR"] = "addr" + i;
            table.Rows.Add(newRow);
          }
          // apply the inserts to the underlying GemFireXD table
          adapter.Update(table);

          // check the inserts
          VerifyInserts(conn, s_numInserts);

        } finally {
          // drop the table
          cmd = new GFXDCommand("drop table t1", conn);
          cmd.ExecuteNonQuery();

          conn.Close();
        }
      }
    }
Ejemplo n.º 43
0
    public void MultipleStringsBatch()
    {
      // Open a new connection to the network server running on localhost
      string host = "localhost";
      int port = s_clientPort;
      string connStr = string.Format("server={0}:{1}", host, port);
      using (GFXDClientConnection conn = new GFXDClientConnection(connStr)) {
        conn.Open();

        // create a table
        GFXDCommand cmd = new GFXDCommand("create table t1 (id int primary" +
                                          " key, addr varchar(20))", conn);
        cmd.ExecuteNonQuery();

        try {
          string cmdStr;
          // insert into the table using different command strings
          for (int i = 0; i < s_numInserts; i++) {
            cmdStr = "insert into t1 values (" + i + ", 'addr" + i + "')";
            cmd.AddBatch(cmdStr);
          }
          int[] results = cmd.ExecuteBatch();

          // check the inserts
          Assert.AreEqual(s_numInserts, results.Length);
          for (int i = 0; i < s_numInserts; i++) {
            Assert.AreEqual(1, results[i], "unexpected result=" + results[i] +
                            " for i=" + i);
          }
          // also check in the database
          VerifyInserts(conn, s_numInserts);

        } finally {
          // drop the table
          cmd = new GFXDCommand("drop table t1", conn);
          cmd.ExecuteNonQuery();

          conn.Close();
        }
      }
    }
Ejemplo n.º 44
0
    public void PositionalParameters()
    {
      // Open a new connection to the network server running on localhost
      string host = "localhost";
      int port = s_clientPort;
      string connStr = string.Format("server={0}:{1}", host, port);
      using (GFXDClientConnection conn = new GFXDClientConnection(connStr)) {
        conn.Open();

        // create a table
        GFXDCommand cmd = new GFXDCommand("create table t1 (id int primary" +
                                          " key, addr varchar(20))", conn);
        cmd.ExecuteNonQuery();

        try {
          // insert into the table using positional parameters
          cmd = new GFXDCommand("insert into t1 (id, addr) values (?, ?)",
                                conn);
          cmd.Prepare();
          for (int i = 0; i < s_numInserts; i++) {
            cmd.Parameters.Clear();
            cmd.Parameters.Add(i);
            cmd.Parameters.Add("addr" + i);

            cmd.ExecuteNonQuery();
          }

          // check the inserts
          VerifyInserts(conn, s_numInserts);

        } finally {
          // drop the table
          cmd = new GFXDCommand("drop table t1", conn);
          cmd.ExecuteNonQuery();

          conn.Close();
        }
      }
    }
    public void TestPoolConnectionsWithTx()
    {
      if (!isRunningWithPool())
        return;
      // start the locator and 1 server first and let client connect with this server only.      
      Console.WriteLine("Pool test TestPoolConnectionsWithTx");
      StartLocator("/gfxdlocator");

      StartServerWithLocatorPort("/gfxdserver1");

      object storeConnectionObject = null;

      Dictionary<object, bool> conns = new Dictionary<object, bool>();
      Console.WriteLine("test starts");
      using (DbConnection conn1 = OpenNewConnection())
      {
        GFXDClientConnection scc = (GFXDClientConnection)conn1;
        storeConnectionObject = scc.RealPooledConnection;
        conns[scc.RealPooledConnection] = true;
        //create table
        DbCommand cmd = conn1.CreateCommand();

        cmd.CommandText = "create table ORDERS (ID int primary key, " +
          "VOL int NOT NULL unique, SECURITY_ID varchar(10)) " +
          "REPLICATE ";

        Log(cmd.CommandText);
        cmd.ExecuteNonQuery();
        conn1.Close();
      }

      for (int i = 0; i < 10; i++)
      {
        DbConnection conn = OpenNewConnection();

        GFXDClientConnection scc = (GFXDClientConnection)conn;
        Log("Conenctions " + scc.PoolConnectionCount + " stored one " + storeConnectionObject.GetHashCode() + " newone:" + scc.RealPooledConnection.GetHashCode());
        conns[scc.RealPooledConnection] = true;

        GFXDTransaction tran = (GFXDTransaction)conn.BeginTransaction(IsolationLevel
                                                       .ReadCommitted);

        DbCommand cmd = new GFXDCommand("INSERT INTO ORDERS VALUES (?, ?, ?)" , (GFXDConnection)conn);
        cmd.Prepare();
        
        cmd.Parameters.Add(i);
        cmd.Parameters.Add(i);
        string str = "Char " + i;
        cmd.Parameters.Add(str);
        Assert.AreEqual(1, cmd.ExecuteNonQuery());
        tran.Commit();
        conn.Close();
      }

      using (DbConnection c2 = OpenNewConnection())
      {
        GFXDClientConnection scc = (GFXDClientConnection)c2;
        Assert.AreEqual(1, scc.PoolConnectionCount);
        Assert.AreEqual(conns.Count, scc.PoolConnectionCount);
        c2.Close();
      }

      // Stop the server where client-connection was established for failover.
      StopServer("/gfxdserver1");

      StopLocator("/gfxdlocator");
    }
Ejemplo n.º 46
0
        public static DataTable GetDataTable(GFXDClientConnection conn, String statement)
        {
            DataTable table = new DataTable();
            GFXDCommand cmd = new GFXDCommand(statement, conn);
            GFXDDataAdapter adpt = cmd.CreateDataAdapter();

            adpt.Fill(table);

            return table;
        }