Ejemplo n.º 1
0
def test_favorite_query_multiline_statement(executor):
    set_expanded_output(False)
    run(executor, "create table test(a text)")
    run(executor, "insert into test values('abc')")
    run(executor, "insert into test values('def')")

    results = run(executor, "\\fs test-ad select * from test where a like 'a%';\n"
                            "select * from test where a like 'd%'")
    assert results == ['Saved.']

    results = run(executor, "\\f test-ad", join=True)
    assert results == dedent("""\
           > select * from test where a like 'a%'
           +-----+
           | a   |
           |-----|
           | abc |
           +-----+
           > select * from test where a like 'd%'
           +-----+
           | a   |
           |-----|
           | def |
           +-----+""")

    results = run(executor, "\\fd test-ad")
    assert results == ['test-ad: Deleted']
Ejemplo n.º 2
0
def test_favorite_query_multiple_statement(executor):
    set_expanded_output(False)
    run(executor, "create table test(a text)")
    run(executor, "insert into test values('abc')")
    run(executor, "insert into test values('def')")

    results = run(
        executor,
        "\\fs test-ad select * from test where a like 'a%'; "
        "select * from test where a like 'd%'",
    )
    assert_result_equal(results, status="Saved.")

    results = run(executor, "\\f test-ad")
    expected = [
        {
            "title": "> select * from test where a like 'a%'",
            "headers": ["a"],
            "rows": [("abc", )],
            "status": None,
        },
        {
            "title": "> select * from test where a like 'd%'",
            "headers": ["a"],
            "rows": [("def", )],
            "status": None,
        },
    ]
    assert expected == results

    results = run(executor, "\\fd test-ad")
    assert_result_equal(results, status="test-ad: Deleted")
Ejemplo n.º 3
0
def test_favorite_query_multiline_statement(executor):
    set_expanded_output(False)
    run(executor, "create table test(a text)")
    run(executor, "insert into test values('abc')")
    run(executor, "insert into test values('def')")

    results = run(
        executor, "\\fs test-ad select * from test where a like 'a%';\n"
        "select * from test where a like 'd%'")
    assert results == ['Saved.']

    results = run(executor, "\\f test-ad", join=True)
    assert results == dedent("""\
           > select * from test where a like 'a%'
           +-----+
           | a   |
           |-----|
           | abc |
           +-----+
           > select * from test where a like 'd%'
           +-----+
           | a   |
           |-----|
           | def |
           +-----+""")

    results = run(executor, "\\fd test-ad")
    assert results == ['test-ad: Deleted']
Ejemplo n.º 4
0
def test_favorite_query_expanded_output(executor):
    set_expanded_output(False)
    run(executor, '''create table test(a text)''')
    run(executor, '''insert into test values('abc')''')

    results = run(executor, "\\fs test-ae select * from test")
    assert results == ['Saved.']

    results = run(executor, "\\f test-ae \G", join=True)

    expected_results = set([
        dedent("""\
        > select * from test
        -[ RECORD 0 ]
        a | abc
        """),
        dedent("""\
        > select * from test
        ***************************[ 1. row ]***************************
        a | abc
        """),
    ])
    set_expanded_output(False)

    assert results in expected_results

    results = run(executor, "\\fd test-ae")
    assert results == ['test-ae: Deleted']
Ejemplo n.º 5
0
def test_shell_parameterized_favorite_query(executor):
    set_expanded_output(False)
    run(executor, "create table test(a text, id integer)")
    run(executor, "insert into test values('abc', 1)")
    run(executor, "insert into test values('def', 2)")

    results = run(executor, "\\fs sh_param select * from test where id=$1")
    assert_result_equal(results, status="Saved.")

    results = run(executor, "\\f sh_param 1")
    assert_result_equal(
        results,
        title="> select * from test where id=1",
        headers=["a", "id"],
        rows=[("abc", 1)],
        auto_status=False,
    )

    results = run(executor, "\\f sh_param")
    assert_result_equal(
        results,
        title=None,
        headers=None,
        rows=None,
        status="missing substitution for $1 in query:\n  select * from test where id=$1",
    )

    results = run(executor, "\\f sh_param 1 2")
    assert_result_equal(
        results,
        title=None,
        headers=None,
        rows=None,
        status="Too many arguments.\nQuery does not have enough place holders to substitute.\nselect * from test where id=1",
    )
Ejemplo n.º 6
0
def test_favorite_query_expanded_output(executor):
    set_expanded_output(False)
    run(executor, '''create table test(a text)''')
    run(executor, '''insert into test values('abc')''')

    results = run(executor, "\\fs test-ae select * from test")
    assert results == ['Saved.']

    results = run(executor, "\\f test-ae \G", join=True)

    expected_results = set([
        dedent("""\
        > select * from test
        -[ RECORD 0 ]
        a | abc
        """),
        dedent("""\
        > select * from test
        ***************************[ 1. row ]***************************
        a | abc
        """),
    ])
    set_expanded_output(False)

    assert results in expected_results

    results = run(executor, "\\fd test-ae")
    assert results == ['test-ae: Deleted']
Ejemplo n.º 7
0
def test_favorite_query_multiple_statement(executor):
    set_expanded_output(False)
    run(executor, "create table test(a text)")
    run(executor, "insert into test values('abc')")
    run(executor, "insert into test values('def')")

    results = run(
        executor, "\\fs test-ad select * from test where a like 'a%'; "
        "select * from test where a like 'd%'")
    assert_result_equal(results, status='Saved.')

    results = run(executor, "\\f test-ad")
    expected = [{
        'title': "> select * from test where a like 'a%'",
        'headers': ['a'],
        'rows': [('abc', )],
        'status': None
    }, {
        'title': "> select * from test where a like 'd%'",
        'headers': ['a'],
        'rows': [('def', )],
        'status': None
    }]
    assert expected == results

    results = run(executor, "\\fd test-ad")
    assert_result_equal(results, status='test-ad: Deleted')
Ejemplo n.º 8
0
def test_bind_parameterized_favorite_query(executor):
    set_expanded_output(False)
    run(executor, "create table test(name text, id integer)")
    run(executor, "insert into test values('def', 2)")
    run(executor, "insert into test values('two words', 3)")

    results = run(executor, "\\fs q_param select * from test where name=?")
    assert_result_equal(results, status="Saved.")

    results = run(executor, "\\f q_param def")
    assert_result_equal(
        results,
        title="> select * from test where name=?",
        headers=["name", "id"],
        rows=[("def", 2)],
        auto_status=False,
    )

    results = run(executor, "\\f q_param 'two words'")
    assert_result_equal(
        results,
        title="> select * from test where name=?",
        headers=["name", "id"],
        rows=[("two words", 3)],
        auto_status=False,
    )

    with pytest.raises(ProgrammingError):
        results = run(executor, "\\f q_param")

    with pytest.raises(ProgrammingError):
        results = run(executor, "\\f q_param 1 2")
Ejemplo n.º 9
0
def test_verbose_feature_of_favorite_query(executor):
    set_expanded_output(False)
    run(executor, "create table test(a text, id integer)")
    run(executor, "insert into test values('abc', 1)")
    run(executor, "insert into test values('def', 2)")

    results = run(executor, "\\fs sh_param select * from test where id=$1")
    assert_result_equal(results, status="Saved.")

    results = run(executor, "\\f sh_param 1")
    assert_result_equal(
        results,
        title=None,
        headers=["a", "id"],
        rows=[("abc", 1)],
        auto_status=False,
    )

    results = run(executor, "\\f+ sh_param 1")
    assert_result_equal(
        results,
        title="> select * from test where id=1",
        headers=["a", "id"],
        rows=[("abc", 1)],
        auto_status=False,
    )
Ejemplo n.º 10
0
def test_favorite_query(executor):
    set_expanded_output(False)
    run(executor, "create table test(a text)")
    run(executor, "insert into test values('abc')")
    run(executor, "insert into test values('def')")

    results = run(executor, "\\fs test-a select * from test where a like 'a%'")
    assert_result_equal(results, status='Saved.')

    results = run(executor, "\\f test-a")
    assert_result_equal(results,
                        title="> select * from test where a like 'a%'",
                        headers=['a'], rows=[('abc',)], auto_status=False)

    results = run(executor, "\\fd test-a")
    assert_result_equal(results, status='test-a: Deleted')
Ejemplo n.º 11
0
def test_favorite_query(executor):
    set_expanded_output(False)
    run(executor, "create table test(a text)")
    run(executor, "insert into test values('abc')")
    run(executor, "insert into test values('def')")

    results = run(executor, "\\fs test-a select * from test where a like 'a%'")
    assert_result_equal(results, status='Saved.')

    results = run(executor, "\\f test-a")
    assert_result_equal(results,
                        title="> select * from test where a like 'a%'",
                        headers=['a'], rows=[('abc',)], auto_status=False)

    results = run(executor, "\\fd test-a")
    assert_result_equal(results, status='test-a: Deleted')
Ejemplo n.º 12
0
def test_favorite_query_expanded_output(executor):
    set_expanded_output(False)
    run(executor, '''create table test(a text)''')
    run(executor, '''insert into test values('abc')''')

    results = run(executor, "\\fs test-ae select * from test")
    assert_result_equal(results, status='Saved.')

    results = run(executor, "\\f test-ae \G")
    assert is_expanded_output() is True
    assert_result_equal(results, title='> select * from test',
                        headers=['a'], rows=[('abc',)], auto_status=False)

    set_expanded_output(False)

    results = run(executor, "\\fd test-ae")
    assert_result_equal(results, status='test-ae: Deleted')
Ejemplo n.º 13
0
def test_favorite_query_expanded_output(executor):
    set_expanded_output(False)
    run(executor, '''create table test(a text)''')
    run(executor, '''insert into test values('abc')''')

    results = run(executor, "\\fs test-ae select * from test")
    assert_result_equal(results, status='Saved.')

    results = run(executor, "\\f test-ae \G")
    assert is_expanded_output() is True
    assert_result_equal(results, title='> select * from test',
                        headers=['a'], rows=[('abc',)], auto_status=False)

    set_expanded_output(False)

    results = run(executor, "\\fd test-ae")
    assert_result_equal(results, status='test-ae: Deleted')
Ejemplo n.º 14
0
def test_favorite_query(executor):
    set_expanded_output(False)
    run(executor, "create table test(a text)")
    run(executor, "insert into test values('abc')")
    run(executor, "insert into test values('def')")

    results = run(executor, "\\fs test-a select * from test where a like 'a%'")
    assert results == ['Saved.']

    results = run(executor, "\\f test-a", join=True)
    assert results == dedent("""\
           > select * from test where a like 'a%'
           +-----+
           | a   |
           +-----+
           | abc |
           +-----+""")

    results = run(executor, "\\fd test-a")
    assert results == ['test-a: Deleted']
Ejemplo n.º 15
0
def test_favorite_query_multiple_statement(executor):
    set_expanded_output(False)
    run(executor, "create table test(a text)")
    run(executor, "insert into test values('abc')")
    run(executor, "insert into test values('def')")

    results = run(executor,
                  "\\fs test-ad select * from test where a like 'a%'; "
                  "select * from test where a like 'd%'")
    assert_result_equal(results, status='Saved.')

    results = run(executor, "\\f test-ad")
    expected = [{'title': "> select * from test where a like 'a%'",
                 'headers': ['a'], 'rows': [('abc',)], 'status': None},
                {'title': "> select * from test where a like 'd%'",
                 'headers': ['a'], 'rows': [('def',)], 'status': None}]
    assert expected == results

    results = run(executor, "\\fd test-ad")
    assert_result_equal(results, status='test-ad: Deleted')
Ejemplo n.º 16
0
def test_favorite_query_expanded_output(executor):
    set_expanded_output(False)
    run(executor, """create table test(a text)""")
    run(executor, """insert into test values('abc')""")

    results = run(executor, "\\fs test-ae select * from test")
    assert_result_equal(results, status="Saved.")

    results = run(executor, "\\f test-ae \G")
    assert is_expanded_output() is True
    assert_result_equal(
        results,
        title="> select * from test",
        headers=["a"],
        rows=[("abc", )],
        auto_status=False,
    )

    set_expanded_output(False)

    results = run(executor, "\\fd test-ae")
    assert_result_equal(results, status="test-ae: Deleted")