create an engine connected to a oracle database using cx_oracle.
979717
def create_oracle(username, password, host, port, database, **kwargs):  # pragma: no cover
    
    return create_engine(
        _create_oracle(username, password, host, port, database),
        **kwargs
    )
1333680
def create_postgresql(username, password, host, port, database, **kwargs):  # pragma: no cover
    
    return create_engine(
        _create_postgresql(username, password, host, port, database),
        **kwargs
    )
836226
def create_table(self, model_class):
        '''
        
        '''
        if model_class.is_system_model():
            raise DatabaseException("You can't create system table")
        if getattr(model_class, 'engine') is None:
            raise DatabaseException("%s class must define an engine" % model_class.__name__)
        self._send(model_class.create_table_sql(self))
1140633
def _connect(uri):
    '''
    
    '''
    # cx_Oracle.Connection() does not support 'as sysdba' syntax
    uri_l = uri.rsplit(' as ', 1)
    if len(uri_l) == 2:
        credentials, mode = uri_l
        mode = MODE[mode]
    else:
        credentials = uri_l[0]
        mode = 0
    # force UTF-8 client encoding
    os.environ['NLS_LANG'] = '.AL32UTF8'
    if '@' in uri:
        serv_name = False
        userpass, hostportsid = credentials.split('@')
        user, password = userpass.split('/')
        hostport, sid = hostportsid.split('/')
        if 'servicename' in sid:
            serv_name = True
            sid = sid.split('servicename')[0].strip()
        hostport_l = hostport.split(':')
        if len(hostport_l) == 2:
            host, port = hostport_l
        else:
            host = hostport_l[0]
            port = 1521
        log.debug('connect: %s', (user, password, host, port, sid, mode))
        if serv_name:
            conn = cx_Oracle.connect(user, password, cx_Oracle.makedsn(host, port, service_name=sid), mode)
        else:
            conn = cx_Oracle.connect(user, password, cx_Oracle.makedsn(host, port, sid), mode)
    else:
        sid = uri.rsplit(' as ', 1)[0]
        orahome = _parse_oratab(sid)
        if orahome:
            os.environ['ORACLE_HOME'] = orahome
        else:
            raise CommandExecutionError('No uri defined and SID {0} not found in oratab'.format(sid))
        os.environ['ORACLE_SID'] = sid
        log.debug('connect: %s', (sid, mode))
        conn = cx_Oracle.connect(mode=MODE['sysdba'])
    conn.outputtypehandler = _unicode_output
    return conn
97459
def connectDb(engine   = dbeng,
              user     = dbuser,
              password = dbpwd,
              host     = dbhost,
              port     = dbport,
              database = dbname,
              params   = "?charset=utf8&use_unicode=1",
              echoopt  = False):
    
    return create_engine('%s://%s:%s@%s:%s/%s%s' % (engine, user, password, host, port, database, params), echo=echoopt)
1157818
def create_app(name, engine):
    
    try:
        if engine.lower() == "sqlalchemy":
            url = urlopen(SQLA_REPO_URL)
            dirname = "Flask-AppBuilder-Skeleton-master"
        elif engine.lower() == "mongoengine":
            url = urlopen(MONGOENGIE_REPO_URL)
            dirname = "Flask-AppBuilder-Skeleton-me-master"
        zipfile = ZipFile(BytesIO(url.read()))
        zipfile.extractall()
        os.rename(dirname, name)
        click.echo(click.style("Downloaded the skeleton app, good coding!", fg="green"))
        return True
    except Exception as e:
        click.echo(click.style("Something went wrong {0}".format(e), fg="red"))
        if engine.lower() == "sqlalchemy":
            click.echo(
                click.style(
                    "Try downloading from {0}".format(SQLA_REPO_URL), fg="green"
                )
            )
        elif engine.lower() == "mongoengine":
            click.echo(
                click.style(
                    "Try downloading from {0}".format(MONGOENGIE_REPO_URL), fg="green"
                )
            )
        return False
1159699
def database_caller_creator(self, number_of_rows, username, password, host, port, name=None, custom=None):
        '''
        '''
        cursor = None
        conn = None

        if name:
            dbname = name
        else:
            dbname = 'postgresql_' + str_generator(self).lower()
        try:
            # createdb
            conn = psycopg2.connect(
                user=username, password=password, host=host, port=port)
            conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
            cur = conn.cursor()
            cur.execute('CREATE DATABASE %s;' % dbname)
            cur.close()
            conn.close()
            # reconnect to the new database
            conn = psycopg2.connect(user=username, password=password,
                                    host=host, port=port, database=dbname)
            cursor = conn.cursor()
            logger.warning('Database created and opened succesfully: %s' % dbname, extra=d)
        except Exception as err:
            logger.error(err, extra=d)
            raise

        if custom:
            self.custom_db_creator(number_of_rows, cursor, conn, custom)
            cursor.close()
            conn.close()
            sys.exit(0)

        return cursor, conn
1076436
def dump_orm_object_as_insert_sql(engine: Engine,
                                  obj: object,
                                  fileobj: TextIO) -> None:
    
    # literal_query = make_literal_query_fn(engine.dialect)
    insp = inspect(obj)
    # insp: an InstanceState
    # http://docs.sqlalchemy.org/en/latest/orm/internals.html#sqlalchemy.orm.state.InstanceState  # noqa
    # insp.mapper: a Mapper
    # http://docs.sqlalchemy.org/en/latest/orm/mapping_api.html#sqlalchemy.orm.mapper.Mapper  # noqa

    # Don't do this:
    #   table = insp.mapper.mapped_table
    # Do this instead. The method above gives you fancy data types like list
    # and Arrow on the Python side. We want the bog-standard datatypes drawn
    # from the database itself.
    meta = MetaData(bind=engine)
    table_name = insp.mapper.mapped_table.name
    # log.debug("table_name: {}", table_name)
    table = Table(table_name, meta, autoload=True)
    # log.debug("table: {}", table)

    # NewRecord = quick_mapper(table)
    # columns = table.columns.keys()
    query = select(table.columns)
    # log.debug("query: {}", query)
    for orm_pkcol in insp.mapper.primary_key:
        core_pkcol = table.columns.get(orm_pkcol.name)
        pkval = getattr(obj, orm_pkcol.name)
        query = query.where(core_pkcol == pkval)
    # log.debug("query: {}", query)
    cursor = engine.execute(query)
    row = cursor.fetchone()  # should only be one...
    row_dict = dict(row)
    # log.debug("obj: {}", obj)
    # log.debug("row_dict: {}", row_dict)
    statement = table.insert(values=row_dict)
    # insert_str = literal_query(statement)
    insert_str = get_literal_query(statement, bind=engine)
    writeline_nl(fileobj, insert_str)
660286
def execute(self, sql, params=None):
        
        # wrap in a transaction to ensure things are committed
        # https://github.com/smnorris/pgdata/issues/3
        with self.engine.begin() as conn:
            result = conn.execute(sql, params)
        return result
385862
def create_table(cls):
        
        schema_editor = getattr(connection, 'schema_editor', None)
        if schema_editor:
            with schema_editor() as schema_editor:
                schema_editor.create_model(cls)
        else:
            raw_sql, _ = connection.creation.sql_create_model(
                cls,
                no_style(),
                [])
            cls.delete_table()
            cursor = connection.cursor()
            try:
                cursor.execute(*raw_sql)
            finally:
                cursor.close()
1076570
def get_engine(self, app=None, bind=None):
        """"""

        app = self.get_app(app)
        state = get_state(app)

        with self._engine_lock:
            connector = state.connectors.get(bind)

            if connector is None:
                connector = self.make_connector(app, bind)
                state.connectors[bind] = connector

            return connector.get_engine()
538020
def create_mysql_oursql(username, password, host, port, database, **kwargs):  # pragma: no cover
    
    return create_engine(
        _create_mysql_oursql(username, password, host, port, database),
        **kwargs
    )
84350
private void createLeaseTable(Connection conn) throws SQLException
    {
        if (tc.isEntryEnabled())
            Tr.entry(tc, "createLeaseTable", new java.lang.Object[] { conn, this });

        Statement createTableStmt = null;
        PreparedStatement specStatement = null;

        try
        {
            createTableStmt = conn.createStatement();

            if (_isOracle)
            {
                String oracleTableString = oracleTablePreString + _leaseTableName + oracleTablePostString;
                if (tc.isDebugEnabled())
                    Tr.debug(tc, "Create Oracle Table using: " + oracleTableString);
                createTableStmt.executeUpdate(oracleTableString);
            }
            else
            {
                String db2TableString = db2TablePreString + _leaseTableName + db2TablePostString;
                if (tc.isDebugEnabled())
                    Tr.debug(tc, "Create DB2 Table using: " + db2TableString);
                createTableStmt.executeUpdate(db2TableString);
            }

        } finally
        {
            if (createTableStmt != null && !createTableStmt.isClosed())
            {
                createTableStmt.close();
            }
            if (specStatement != null && !specStatement.isClosed())
            {
                specStatement.close();
            }
        }

        if (tc.isEntryEnabled())
            Tr.exit(tc, "createLeaseTable");
    }
889378
def create_database_session(engine):
    """"""

    try:
        Session = sessionmaker(bind=engine)
        return Session()
    except OperationalError as e:
        raise DatabaseError(error=e.orig.args[1], code=e.orig.args[0])
809829
def create_tables(args):
  """"""

  from bob.db.utils import create_engine_try_nolock
  engine = create_engine_try_nolock(args.type, args.files[0], echo=(args.verbose > 2))
  Base.metadata.create_all(engine)
725762
def init():
    """"""
    click.secho('Creating database {0}'.format(_db.engine.url),
                fg='green')
    if not database_exists(str(_db.engine.url)):
        create_database(str(_db.engine.url))
911440
def init_db():
    """"""
    import reana_db.models
    if not database_exists(engine.url):
        create_database(engine.url)
    Base.metadata.create_all(bind=engine)