示例#1
0
        public void SelectBlob(MySQLConnection con)
        {
            try
            {
                con.Open();

                MySQLCommand cmd = new MySQLCommand("select col1, col2 from `trntipos` where col1=3", con);                //, `SerialNumberLastUsed`
                cmd.UsePreparedStatement = true;
                cmd.ServerCursor         = true;
                cmd.Prepare();
                MySQLDataReader reader = (MySQLDataReader)cmd.ExecuteReader();
                while (reader.Read())
                {
                    getBLOBFile("output.jpg", reader, 1);
                }
                reader.Close();

                cmd.Dispose();
                con.Close();
            }
            catch (Exception e)
            {
                if (con != null)
                {
                    con.Close();
                }
                throw e;
            }
        }
示例#2
0
        public void InsertBlob(MySQLConnection con)
        {
            try
            {
                con.Open();

                MySQLCommand   cmd = new MySQLCommand("INSERT INTO `trntipos`(col1, col2) values (?, ?)", con);              //, `SerialNumberLastUsed`
                MySQLParameter p1  = new MySQLParameter("@col1", DbType.Int32);
                MySQLParameter p2  = new MySQLParameter("@col2", DbType.Binary);
                p2.Value = GetBinary(@"myblob.jpg");
                p1.Value = 1;
                cmd.UsePreparedStatement = true;
                cmd.Parameters.Add(p1);
                cmd.Parameters.Add(p2);
                cmd.Prepare();
                int affectedrows = cmd.ExecuteNonQuery();

                cmd.Dispose();
                con.Close();
            }
            catch (Exception e)
            {
                if (con != null)
                {
                    con.Close();
                }
                throw e;
            }
        }
示例#3
0
        public int TestSelect(MySQLConnection con, bool useNew)
        {
            int affectedrows = 0;

            try
            {
                con.Open();

                MySQLCommand cmd = new MySQLCommand("SELECT col1, col2, col3, col4 FROM `test_table`", con);
                if (useNew)
                {
                    cmd.UsePreparedStatement = true;
                    cmd.ServerCursor         = true;
                    cmd.Prepare();
                }
                IDataReader  reader = cmd.ExecuteReader();
                MySQLCommand cmd1   = new MySQLCommand("SELECT col1, col2, col3, col4 FROM `test_table`", con);
                if (useNew)
                {
                    cmd1.UsePreparedStatement = true;
                    //cmd.ServerCursor = true;
                    cmd.FetchSize = 10;
                    cmd1.Prepare();
                }
                while (reader.Read())
                {
                    affectedrows++;
                    IDataReader reader1 = cmd1.ExecuteReader();
                    while (reader1.Read())
                    {
                        affectedrows++;
                        long     s1  = reader1.GetInt64(0);
                        string   st1 = reader1.GetString(1);
                        DateTime dt1 = reader1.GetDateTime(3);
                    }
                    reader1.Close();

                    long     s  = reader.GetInt64(0);
                    string   st = reader.GetString(1);
                    DateTime dt = reader.GetDateTime(3);
                }
                reader.Close();
                cmd.Dispose();
                con.Close();
                return(affectedrows);
            }
            catch (Exception e)
            {
                if (con != null)
                {
                    con.Close();
                }
                throw e;
            }
        }
示例#4
0
        public int InsertTest(MySQLConnection con, bool useNew)
        {
            try
            {
                con.Open();

                MySQLCommand cmd;
                if (useNew)
                {
                    cmd = new MySQLCommand("INSERT INTO `test_table` (col1, col2, col3, col4) values (?,?,?,?)", con);                    //, `SerialNumberLastUsed`
                    cmd.UsePreparedStatement = true;
                    cmd.ServerCursor         = false;
                    cmd.Prepare();
                }
                else
                {
                    cmd = new MySQLCommand("INSERT INTO `test_table`(col1, col2, col3, col4) values (@col1, @col2, @col3, @col4)", con);                    //, `SerialNumberLastUsed`
                }

                MySQLParameter p1 = new MySQLParameter("@col1", DbType.Int32);
                cmd.Parameters.Add(p1);
                MySQLParameter p2 = new MySQLParameter("@col2", DbType.String);
                cmd.Parameters.Add(p2);
                MySQLParameter p3 = new MySQLParameter("@col1", DbType.Int16);
                cmd.Parameters.Add(p3);
                MySQLParameter p4 = new MySQLParameter("@col4", DbType.DateTime);
                cmd.Parameters.Add(p4);
                int affectedrows = 0;
                for (int i = 0; i < count; i++)
                {
                    p4.Value      = DateTime.Now;
                    p1.Value      = i;
                    p2.Value      = "Registro número " + i;
                    p2.Size       = p2.Value.ToString().Length;
                    p3.Value      = i * 10;
                    affectedrows += cmd.ExecuteNonQuery();
                }
                cmd.Dispose();
                con.Close();
                return(affectedrows);
            }
            catch (Exception e)
            {
                if (con != null)
                {
                    con.Close();
                }
                throw e;
            }
        }
        public override IDbCommand GetCommand(IGxConnection con, string stmt, GxParameterCollection parameters, bool isCursor, bool forFirst, bool isRpc)
        {
            if (isRpc)
            {
                stmt = convertToMySqlCall(stmt, parameters);
            }
            MySQLCommand mysqlcmd = (MySQLCommand)base.GetCommand(con, stmt, parameters);

            if (preparedStmts && isCursor && !isRpc)
            {
                mysqlcmd.UsePreparedStatement = true;
                mysqlcmd.Prepare();
            }
            return(mysqlcmd);
        }
示例#6
0
        public void Test(MySQLConnection con)
        {
            try
            {
                con.Open();

                MySQLCommand cmd = new MySQLCommand("SELECT col1, col2, col3, col4 FROM `test_table`", con);                //, `SerialNumberLastUsed`
                cmd.UsePreparedStatement = true;
                cmd.ServerCursor         = true;
                cmd.Prepare();

                MySQLCommand cmd1   = new MySQLCommand("SELECT col1, col2 FROM `test_table`", con);              //SerialNumberID
                IDataReader  reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    IDataReader reader1 = cmd1.ExecuteReader();

                    while (reader1.Read())
                    {
                        Console.Write(reader1.GetInt32(0) + " ");
                        Console.WriteLine(reader1.GetString(1));
                    }
                    reader1.Close();

                    Console.Write(reader.GetInt32(0) + " ");

                    Console.WriteLine(reader.GetString(1));
                    Console.WriteLine(reader.GetDateTime(3));
                    Console.WriteLine(reader.IsDBNull(2));
                    Console.WriteLine(reader.GetInt16(2));
                    Console.WriteLine(reader.IsDBNull(0));
                }
                reader.Close();
                cmd1.Dispose();
                cmd.Dispose();
                con.Close();
            }
            catch (Exception e)
            {
                if (con != null)
                {
                    con.Close();
                }
                throw e;
            }
        }