当前位置: 首页>>代码示例>>Python>>正文


Python sqlparse.format函数代码示例

本文整理汇总了Python中sqlparse.format函数的典型用法代码示例。如果您正苦于以下问题:Python format函数的具体用法?Python format怎么用?Python format使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了format函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_issue40

def test_issue40():
    # make sure identifier lists in subselects are grouped
    p = sqlparse.parse(('SELECT id, name FROM '
                        '(SELECT id, name FROM bar) as foo'))[0]
    assert len(p.tokens) == 7
    assert p.tokens[2].__class__ == sql.IdentifierList
    assert p.tokens[-1].__class__ == sql.Identifier
    assert p.tokens[-1].get_name() == 'foo'
    sp = p.tokens[-1].tokens[0]
    assert sp.tokens[3].__class__ == sql.IdentifierList
    # make sure that formatting works as expected
    s = sqlparse.format('SELECT id ==  name FROM '
                        '(SELECT id, name FROM bar)', reindent=True)
    assert s == '\n'.join([
        'SELECT id == name',
        'FROM',
        '  (SELECT id,',
        '          name',
        '   FROM bar)'])

    s = sqlparse.format('SELECT id ==  name FROM '
                        '(SELECT id, name FROM bar) as foo', reindent=True)
    assert s == '\n'.join([
        'SELECT id == name',
        'FROM',
        '  (SELECT id,',
        '          name',
        '   FROM bar) as foo'])
开发者ID:andialbrecht,项目名称:sqlparse,代码行数:28,代码来源:test_regressions.py

示例2: _printSql

	def _printSql(self, q):
		if self.print_sqls:
			self._printLine()
			if HAS_SQLPARSE:
				print sqlparse.format(q, reindent=True, keyword_case='upper')
			else:
				print q
开发者ID:CloudServer,项目名称:postgresql-perf-tools,代码行数:7,代码来源:pg-info.py

示例3: test_issue40

 def test_issue40(self):
     # make sure identifier lists in subselects are grouped
     p = sqlparse.parse(('SELECT id, name FROM '
                         '(SELECT id, name FROM bar) as foo'))[0]
     self.assertEqual(len(p.tokens), 7)
     self.assertEqual(p.tokens[2].__class__, sql.IdentifierList)
     self.assertEqual(p.tokens[-1].__class__, sql.Identifier)
     self.assertEqual(p.tokens[-1].get_name(), u'foo')
     sp = p.tokens[-1].tokens[0]
     self.assertEqual(sp.tokens[3].__class__, sql.IdentifierList)
     # make sure that formatting works as expected
     self.ndiffAssertEqual(
         sqlparse.format(('SELECT id, name FROM '
                          '(SELECT id, name FROM bar)'),
                         reindent=True),
         ('SELECT id,\n'
          '       name\n'
          'FROM\n'
          '  (SELECT id,\n'
          '          name\n'
          '   FROM bar)'))
     self.ndiffAssertEqual(
         sqlparse.format(('SELECT id, name FROM '
                          '(SELECT id, name FROM bar) as foo'),
                         reindent=True),
         ('SELECT id,\n'
          '       name\n'
          'FROM\n'
          '  (SELECT id,\n'
          '          name\n'
          '   FROM bar) as foo'))
开发者ID:ChimmyTee,项目名称:oh-mainline,代码行数:31,代码来源:test_regressions.py

示例4: do_query_tag_report

def do_query_tag_report(query_tag, i, days, start, end, no_show_sql):
    first = True
    print('\nSlow report for tag #{} {}\n'.format(i+1,query_tag))
    for file in gfiles(days, start, end):
        with open(file, 'r') as f:
            date, time = get_report_date(f)
            qdata, sql = head_match(f, query_tag, 70)
            hdata = top_head(f, 70)
            if first:
                first = False
                if not no_show_sql:
                    try:
                        print(sqlparse.format('\n'.join(sql), reindent=True, keyword_case='upper'))
                    except IndexError, e:
                        print(sqlparse.format('\n'.join(sql), keyword_case='upper'))
                    print('')

                print('{0:10} {1:8}  {2:>10}   {3:>9}   {4:>9}   {5:>12}   {6:>11s}  '
                      '{7:>6s}  {8:>12s} {9:>11s} {10:11s}'.format(
                            'Date',
                            'Time',
                            'Count',
                            'Exec_Time',
                            'Lock_Time',
                            'QAve_Resp',
                            '%Qexec_time',  #6
                            '%Count',
                            'Tot_Q_Count',
                            'Tot_time',
                            'Tot_ave_resp'
                            ))
        format_query_tag(date, time, qdata, hdata)
开发者ID:markgruen,项目名称:query-digest-historical-reporter,代码行数:32,代码来源:report_slow.py

示例5: new_linelist_from_gfall

def new_linelist_from_gfall(new_dbname, select_atom=None):
    print "Reading lines from Kurucz gfall"
    conn = sqlite3.connect(new_dbname)
    conn.create_function('pow', 2, math.pow)
    conn.create_function('convert_air2vacuum', 1, convert_air2vacuum)
    curs = conn.cursor()
    curs.execute(sql_stmts.linelist_create_stmt)
    if select_atom is None:
        elem_select_stmt = ""
    else:
        elem_select_stmt = " and elem in (%s)" % (','.join(map(str, select_atom)),)

    insert_fromgfall_stmt = sql_stmts.linelist_insert_stmt + sql_stmts.linelist_select_stmt % {'hc':hc, 'where_stmt':elem_select_stmt}
    
    if sqlparse_available:
        print sqlparse.format(insert_fromgfall_stmt, reindent=True)
    else:
        print insert_fromgfall_stmt
    
    curs.execute(insert_fromgfall_stmt)
    
    conn.commit()
    print "%d lines in database" % (conn.execute('select count(atom) from lines').fetchone()[0])
    print "updating oscillator strengths"
    
    conn.execute(update_oscillator_stmt)
    conn.commit()
    return conn
开发者ID:tardis-sn,项目名称:tardisatomic,代码行数:28,代码来源:construct_atom_db.py

示例6: test_identifiercase

 def test_identifiercase(self):
     sql = 'select * from bar; -- select foo\n'
     res = sqlparse.format(sql, identifier_case='upper')
     assert res == 'select * from BAR; -- select foo\n'
     res = sqlparse.format(sql, identifier_case='capitalize')
     assert res == 'select * from Bar; -- select foo\n'
     res = sqlparse.format(sql.upper(), identifier_case='lower')
     assert res == 'SELECT * FROM bar; -- SELECT FOO\n'
开发者ID:pjdelport,项目名称:sqlparse,代码行数:8,代码来源:test_format.py

示例7: test_php

 def test_php(self):
     sql = 'select * from foo;'
     f = lambda sql: sqlparse.format(sql, output_format='php')
     self.ndiffAssertEqual(f(sql), '$sql = "select * from foo;";')
     f = lambda sql: sqlparse.format(sql, output_format='php',
                                     reindent=True)
     self.ndiffAssertEqual(f(sql), ('$sql  = "select * ";\n'
                                    '$sql .= "from foo;";'))
开发者ID:Greg-J,项目名称:sqlparse,代码行数:8,代码来源:test_format.py

示例8: test_python

 def test_python(self):
     sql = 'select * from foo;'
     f = lambda sql: sqlparse.format(sql, output_format='python')
     self.ndiffAssertEqual(f(sql), "sql = 'select * from foo;'")
     f = lambda sql: sqlparse.format(sql, output_format='python',
                                     reindent=True)
     self.ndiffAssertEqual(f(sql), ("sql = ('select * '\n"
                                    "       'from foo;')"))
开发者ID:Greg-J,项目名称:sqlparse,代码行数:8,代码来源:test_format.py

示例9: test_keywordcase

 def test_keywordcase(self):
     sql = 'select * from bar; -- select foo\n'
     res = sqlparse.format(sql, keyword_case='upper')
     assert res == 'SELECT * FROM bar; -- select foo\n'
     res = sqlparse.format(sql, keyword_case='capitalize')
     assert res == 'Select * From bar; -- select foo\n'
     res = sqlparse.format(sql.upper(), keyword_case='lower')
     assert res == 'select * from BAR; -- SELECT FOO\n'
开发者ID:pjdelport,项目名称:sqlparse,代码行数:8,代码来源:test_format.py

示例10: print_sql

def print_sql(show_queries=True):
    print "Total Run Time: %s"%(datetime.now()-start_time)
    print "Total Postgres Time: %s"%sum([float(query['time']) for query in con.queries[query_count:]])
    print "Queries: %s"%(len(con.queries)-query_count)

    if show_queries:
        for query in con.queries[query_count:]:
            print "\nPostgres Time: %s"%query['time']
            print sqlparse.format(query['sql'], reindent=True, keyword_case='upper')
开发者ID:hobson,项目名称:Efficient-Django-QuerySet-Use,代码行数:9,代码来源:__init__.py

示例11: test_python

 def test_python(self):
     sql = 'select * from foo;'
     f = lambda sql: sqlparse.format(sql, output_format='python')
     assert f(sql) == "sql = 'select * from foo;'"
     f = lambda sql: sqlparse.format(sql, output_format='python',
                                     reindent=True)
     assert f(sql) == '\n'.join([
         "sql = ('select * '",
         "       'from foo;')"])
开发者ID:pjdelport,项目名称:sqlparse,代码行数:9,代码来源:test_format.py

示例12: test_php

 def test_php(self):
     sql = 'select * from foo;'
     f = lambda sql: sqlparse.format(sql, output_format='php')
     assert f(sql) == '$sql = "select * from foo;";'
     f = lambda sql: sqlparse.format(sql, output_format='php',
                                     reindent=True)
     assert f(sql) == '\n'.join([
         '$sql  = "select * ";',
         '$sql .= "from foo;";'])
开发者ID:pjdelport,项目名称:sqlparse,代码行数:9,代码来源:test_format.py

示例13: print_sql

def print_sql(qs):
    q = qs.query.as_sql()
    statement = q[0] % q[1]
    try:
        import sqlparse
        print sqlparse.format(statement, reindent=True, keyword_case='upper')
    except ImportError:
        import warnings
        warnings.warn("sqlparse not installed")
        print statement
开发者ID:peterbe,项目名称:kl,代码行数:10,代码来源:utils.py

示例14: test_strip_comments_single

 def test_strip_comments_single(self):
     sql = 'select *-- statement starts here\nfrom foo'
     res = sqlparse.format(sql, strip_comments=True)
     assert res == 'select * from foo'
     sql = 'select * -- statement starts here\nfrom foo'
     res = sqlparse.format(sql, strip_comments=True)
     assert res == 'select * from foo'
     sql = 'select-- foo\nfrom -- bar\nwhere'
     res = sqlparse.format(sql, strip_comments=True)
     assert res == 'select from where'
开发者ID:pjdelport,项目名称:sqlparse,代码行数:10,代码来源:test_format.py

示例15: test_keywordcase

 def test_keywordcase(self):
     sql = 'select * from bar; -- select foo\n'
     res = sqlparse.format(sql, keyword_case='upper')
     self.ndiffAssertEqual(res, 'SELECT * FROM bar; -- select foo\n')
     res = sqlparse.format(sql, keyword_case='capitalize')
     self.ndiffAssertEqual(res, 'Select * From bar; -- select foo\n')
     res = sqlparse.format(sql.upper(), keyword_case='lower')
     self.ndiffAssertEqual(res, 'select * from BAR; -- SELECT FOO\n')
     self.assertRaises(SQLParseError, sqlparse.format, sql,
                       keyword_case='foo')
开发者ID:Greg-J,项目名称:sqlparse,代码行数:10,代码来源:test_format.py


注:本文中的sqlparse.format函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。