Exemplo n.º 1
0
def get_db_component(request):
    format_ = {'data': [], 'status': 1, 'message': ''}
    db = None

    try:
        source = json.loads(request.POST.get('source', '{}'))

        db = _get_db(request)

        if source['rdbmsType'] != 'jdbc':
            assist = Assist(db)
        else:
            assist = JdbcAssist(db)

        if not source['rdbmsDatabaseName'] or (
                source['rdbmsMode'] == "customRdbms"
                and not source['rdbmsDbIsValid']):
            data = assist.get_databases()
        elif source['rdbmsDatabaseName']:
            data = assist.get_tables(source['rdbmsDatabaseName'])

        format_['data'] = [{
            'name': element,
            'value': element
        } for element in data]
        format_['status'] = 0
    except Exception, e:
        message = _('Error accessing the database: %s') % e
        LOG.warn(message)
        format_['message'] = message
Exemplo n.º 2
0
    def get_sample_data(self,
                        mode=None,
                        database=None,
                        table=None,
                        column=None):
        if self.db:
            db = self.db
        else:
            query_server = rdbms.get_query_server_config(
                server=self.db_conf_name)
            db = rdbms.get(self.user, query_server=query_server)

        if mode == 'configRdbms' or self.db_conf_name != 'jdbc':
            assist = Assist(db)
        else:
            assist = JdbcAssist(db)

        response = {'status': -1}
        sample_data = assist.get_sample_data(database, table, column)

        if sample_data:
            response['status'] = 0
            response['headers'] = sample_data.columns
            response['rows'] = list(sample_data.rows())
        else:
            response['message'] = _('Failed to get sample data.')

        return response
Exemplo n.º 3
0
def get_db_component(request):
  format_ = {'data': [], 'status': 1, 'message': ''}
  db = None

  try:
    source = json.loads(request.POST.get('source', '{}'))
    user = User.objects.get(username=request.user)
    name = None
    if source['rdbmsMode'] == 'configRdbms':
      if source['rdbmsType'] != 'jdbc':
        query_server = rdbms.get_query_server_config(server=source['rdbmsType'])
        db = rdbms.get(user, query_server=query_server)
      else:
        interpreters = get_ordered_interpreters(request.user)
        options = {}
        key = [key for key in interpreters if key['name'] == source['rdbmsJdbcDriverName']]
        if key:
          options = key[0]['options']

          db = Jdbc(driver_name=options['driver'], url=options['url'], username=options['user'], password=options['password'])
    else:
      name = source['rdbmsType']
      if name != 'jdbc':
        query_server = {
          'server_name': name,
          'server_host': source['rdbmsHostname'],
          'server_port': int(source['rdbmsPort']),
          'username': source['rdbmsUsername'],
          'password': source['rdbmsPassword'],
          'options': {},
          'alias': name
        }
        db = rdbms.get(user, query_server=query_server)
      else:
        db = Jdbc(driver_name=source['rdbmsJdbcDriver'], url=source['rdbmsHostname'], username=source['rdbmsUsername'], password=source['rdbmsPassword'])

    if source['rdbmsType'] != 'jdbc':
      assist = Assist(db)
    else:
      assist = JdbcAssist(db)

    if not source['rdbmsDatabaseName']:
      data = assist.get_databases()
    elif source['rdbmsDatabaseName']:
      data = assist.get_tables(source['rdbmsDatabaseName'])

    format_['data'] = [{'name': element, 'value': element} for element in data]
    format_['status'] = 0
  except Exception, e:
    message = _('Error accessing the database %s: %s') % (name, e)
    LOG.warn(message)
    format['message'] = message
Exemplo n.º 4
0
def get_db_component(request):
    format_ = {'data': [], 'status': 1, 'message': ''}
    name = None
    try:
        source = json.loads(request.POST.get('source', '{}'))
        user = User.objects.get(username=request.user)
        if source['rdbmsMode'] == 'configRdbms':
            query_server = rdbms.get_query_server_config(
                server=source['rdbmsType'])
        else:
            name = source['rdbmsType']
            if name:
                query_server = {
                    'server_name': name,
                    'server_host': source['rdbmsHostname'],
                    'server_port': int(source['rdbmsPort']),
                    'username': source['rdbmsUsername'],
                    'password': source['rdbmsPassword'],
                    'options': {},
                    'alias': name
                }

        db = rdbms.get(user, query_server=query_server)
        assist = Assist(db)
        if not source['rdbmsDatabaseName']:
            data = assist.get_databases()
        else:
            data = assist.get_tables(source['rdbmsDatabaseName'])
        format_['data'] = [{
            'name': element,
            'value': element
        } for element in data]
        format_['status'] = 0
    except Exception, e:
        message = 'Error accessing the database %s' % name
        LOG.warn(message, e)
        format['message'] = _(message)