Exemplo n.º 1
0
        /// <inheritdoc />
        public ResultSet <T> Select <T>(string query, Dictionary <string, dynamic> bindings = null) where T : Model <T>, new()
        {
            using var connection = new Connection(ConnectionString);
            connection.Open();

            using var command = new Command(query, connection);
            BindParameters(command, bindings);

            using var reader = command.ExecuteReader();
            ResultSet <T> resultSet = new ResultSet <T>();

            if (Manager.DebugMode)
            {
                Manager.Logger(query);
            }

            while (reader.Read())
            {
                ResultRow <T> resultRow = new ResultRow <T>();

                for (int column = 0; column < reader.FieldCount; column++)
                {
                    resultRow.Columns.Add(reader.GetName(column), reader.GetValue(column));
                }

                resultSet.Rows.Add(resultRow);
            }

            return(resultSet);
        }
Exemplo n.º 2
0
        /// <inheritdoc />
        public void Delete(string query, Dictionary <string, dynamic> bindings = null)
        {
            using var connection = new Connection(ConnectionString);
            connection.Open();

            using var command = new Command(query, connection);
            BindParameters(command, bindings);
            command.ExecuteNonQuery();

            if (Manager.DebugMode)
            {
                Manager.Logger(query);
            }
        }
Exemplo n.º 3
0
        /// <inheritdoc />
        public int Insert(string query, Dictionary <string, dynamic> bindings = null)
        {
            using var connection = new Connection(ConnectionString);
            connection.Open();

            using var command = new Command(query, connection);
            BindParameters(command, bindings);
            command.ExecuteNonQuery();

            if (Manager.DebugMode)
            {
                Manager.Logger(query);
            }

            return(Convert.ToInt32(command.LastInsertedId));
        }
Exemplo n.º 4
0
        public void GlobalSetup()
        {
            using (var connection = new MySqlConnector.MySqlConnection(s_connectionString))
            {
                connection.Open();
                using (var cmd = connection.CreateCommand())
                {
                    cmd.CommandText = @"
create schema if not exists benchmark;

drop table if exists benchmark.integers;
create table benchmark.integers (value int not null primary key);
insert into benchmark.integers(value) values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);

drop table if exists benchmark.blobs;
create table benchmark.blobs(
rowid integer not null primary key auto_increment,
`Blob` longblob null
);
insert into benchmark.blobs(`Blob`) values(null), (@Blob1), (@Blob2);";

                    // larger blobs make the tests run much slower
                    AddBlobParameter(cmd, "@Blob1", 75000);
                    AddBlobParameter(cmd, "@Blob2", 150000);

                    cmd.ExecuteNonQuery();
                }
            }

            s_connectionString += ";database=benchmark";

            var mySqlData = new MySql.Data.MySqlClient.MySqlConnection(s_connectionString);

            mySqlData.Open();
            m_connections.Add("MySql.Data", mySqlData);

            var mySqlConnector = new MySqlConnector.MySqlConnection(s_connectionString);

            mySqlConnector.Open();
            m_connections.Add("MySqlConnector", mySqlConnector);

            Connection = m_connections[Library];
        }