Esempio n. 1
0
        public object ExecuteScalar(string sql, IDictionary <string, object> parameters)
        {
            Sequel.Log("ExecuteScalar('{0}', {1})", sql, parameters == null ? "null" : string.Join(", ", parameters.Select(i => i.Key + " = " + i.Value.ToString()).ToArray()));
            var command = CreateCommand(sql);

            AddCommandParameters(command, parameters);
            using (var connection = command.Connection) {
                connection.Open();
                return(command.ExecuteScalar());
            }
        }
Esempio n. 2
0
        public void ExecuteReader(string sql, IDictionary <string, object> parameters, Action <DbDataReader> action)
        {
            Sequel.Log("ExecuteReader('{0}', {1})", sql, parameters == null ? "null" : string.Join(", ", parameters.Select(i => i.Key + " = " + i.Value.ToString()).ToArray()));
            var command = CreateCommand(sql);

            AddCommandParameters(command, parameters);
            using (var connection = command.Connection) {
                connection.Open();
                using (var reader = command.ExecuteReader())
                    action.Invoke(reader);
            }
        }
 // Right now, this ONLY works if your ConnectionString uses this format:
 //   Initial Catalog=...
 public void Use(string databaseName)
 {
     Sequel.Log("Use('{0}')", databaseName);
     ConnectionString = Regex.Replace(ConnectionString, "Initial Catalog=[^;]+", "Initial Catalog=" + databaseName);
 }