public static OracleCommand GetCommand(QtDbConnection connection, string commandText)
        {
            var oracleConnection = GetConnection(connection);
            var oracleCommand = oracleConnection.CreateCommand();

            if (oracleCommand != null) { }
                oracleCommand.CommandText = commandText;

            oracleCommand.CommandType = CommandType.Text;
            return oracleCommand;
        }
 public QueryResult Execute(Query q, QtDbConnection targetQtDb)
 {
     switch (q.DbType)
     {
         case EnumDatabase.Oracle:
             {
                 return new OracleExecutor().ExecuteRead(targetQtDb,q);
             }
         case EnumDatabase.SqlServer:
             {
                 return new MsSqlServerExecutor().ExecuteRead(targetQtDb,q);
             }
         default:
             throw new NotImplementedException(string.Format("Database type {0} is not supported",q.DbType));
     }
 }
Beispiel #3
0
        public QueryResult ExecuteRead(QtDbConnection targetQtDb, Query query)
        {
            using (var cmd = GetCommand(targetQtDb,query))
            {
                try
                {
                    cmd.Connection.Open();
                    List<Field> fields;
                    var rows = new List<Row>();
                    using (var reader = cmd.ExecuteReader())
                    {
                        fields = GetQueryFieldInfo(reader.GetSchemaTable());
                        var fieldCount = reader.FieldCount;
                        while (reader.Read())
                        {
                            var row = new Row();
                            for (int i = 0; i < fieldCount; i++)
                            {
                                var obj = reader[i];
                                row.AddValue(obj.ToString());
                            }
                            rows.Add(row);
                        }
                    }

                    return new QueryResult()
                               {
                                   Rows = rows,
                                   Fields = fields
                               };
                }
                catch (Exception ex)
                {
                    throw;
                }
                finally
                {
                    cmd.Connection.Close();
                }
            }
        }
Beispiel #4
0
        public static QtDbConnection TryGetConnectionFromString(string dbConnectionKey)
        {
            if (string.IsNullOrEmpty(dbConnectionKey))
            {
                return null;
            }

            var connection = ConfigurationManager.ConnectionStrings[dbConnectionKey];

            if (connection == null)
            {
                throw new ApplicationException(string.Format("Connection can not be found for {0}",dbConnectionKey));
            }

            var connString = ConfigurationManager.ConnectionStrings[dbConnectionKey].ConnectionString;
            var provider = ConfigurationManager.ConnectionStrings[dbConnectionKey].ProviderName;

            EnumDatabase type;
            if (provider.Contains("Oracle"))
            {
                type = EnumDatabase.Oracle;
            }
            else if (provider.Contains("MsSql"))
            {
                type = EnumDatabase.SqlServer;
            }
            else
            {
                throw new NotSupportedException("Datbase type is not supported");
            }

            var dbConnection = new QtDbConnection()
            {
                ConnectionString = connString,
                Name = dbConnectionKey,
                Type = type
            };

            return dbConnection;
        }
Beispiel #5
0
 private OracleCommand GetCommand(QtDbConnection targetQtDb, Query query)
 {
     return OracleCommandCreator.GetCommand(targetQtDb, query.Text);
 }
 public QueryResult ExecuteRead(QtDbConnection targetQtDb, Query query)
 {
     throw new NotImplementedException();
 }
 private static OracleConnection GetConnection(QtDbConnection connection)
 {
     return new OracleConnection(connection.ConnectionString);
 }