コード例 #1
0
 def _ConstructSQLTableCreate(self, values):
   dba = DBAccess()
   if dba.IsTablePresent(self._table_name):
     return ''
   sql_str = "CREATE TABLE %s (" % self._table_name
   for n in range(len(self._colnames)):
     sql_str += "%s %s" % (self._colnames[n], SQLType(values[n]))
     if n+1 >= len(self._colnames):
       sql_str += ")"
     else:
       sql_str += ","
   return sql_str
コード例 #2
0
 def _AddFileToTable(self):
   # Records the file in the Django UploadedFiles table
   dba = DBAccess(db_path=self._db_path)
   if not dba.IsTablePresent(settings.UPLOAD_FILE_TABLE):
     raise DBError('%s does not exist' % settings.UPLOAD_FILE_TABLE)
   sql_str = "SELECT * from %s where table_name='%s'" % (
     settings.UPLOAD_FILE_TABLE, self._filename)
   rows, _ = dba.ExecuteQuery(sql_str)
   if len(rows) == 0:
     sql_str = '''
          INSERT into %s ('file_name', 'file_path', 'table_name')
          VALUES ('%s', '%s', '%s')
          ''' % (settings.UPLOAD_FILE_TABLE,
                 self._filename, 
                 self._file_path, 
                 self._table_name)
     dba.ExecuteQuery(sql_str, commit=True)
コード例 #3
0
def maketable(request):
  table_list = FileTable.DataTableList(CUR_DB)
  if request.method == 'POST':
    tablename = request.POST['tablename']
    table_list.remove(tablename)
    table_list.insert(0, tablename)  # Make sure it's the default
    # Create a form instance and populate it with data from the request:
    display_form = TableForm(request.POST)
    # check whether it's valid:
    if display_form.is_valid():
      numrows = GetFieldFromForm(display_form, 'numrows')
      lastrow = GetFieldFromForm(display_form, 'lastrow')
      dba = DBAccess()
      if not dba.IsTablePresent(tablename): 
        raise TableviewUserError("Cannot find table %s" % tablename)
      headers = dba.GetSchema(tablename)
      sql_str = 'SELECT * FROM %s' % tablename 
      all_rows, _ = dba.ExecuteQuery(sql_str)
      if 'Next' in request.POST:
        firstrow = lastrow + 1
      else:
        firstrow = lastrow - 2*numrows
      lastrow = firstrow + numrows - 1
      rows = all_rows[firstrow-1:lastrow-1]
      new_display_form = TableForm(initial={
          'numrows': numrows, 'lastrow': lastrow})
      ctx_dict = {'rows':rows, 
          'display_form': new_display_form, 
          'tablename': tablename,
          'headers': headers,
          'table_list': table_list,
          }
      return render_to_response('table_view.html', ctx_dict, 
          context_instance=RequestContext(request))
    else:
      pass

  # if a GET (or any other method) we'll create a blank form
  else:
    display_form = TableForm()

  return render(request, 'table_request.html', 
      {'display_form': display_form,
       'table_list': table_list})