Example #1
0
 def test_customsql(self, tables):
     tables.set('t')
     tables.join('u').on('col', sqlpuzzle.customsql('x'))
     assert str(tables) == '"t" JOIN "u" ON "col" = x'
Example #2
0
def test_custom_more_tables(tables):
    customsql = sqlpuzzle.customsql('"custom" JOIN "sql"')
    tables.set(customsql, 'id')
    assert str(tables) == '"custom" JOIN "sql", "id"'
 def setUp(self):
     super(CustomSqlTest, self).setUp()
     self.customsql = sqlpuzzle.customsql('"age" = "age" + 1')
Example #4
0
 def setUp(self):
     super(CustomSqlTest, self).setUp()
     self.customsql = sqlpuzzle.customsql('"custom" JOIN "sql"')
Example #5
0
def test_custom_more_columns(columns):
    customsql = sqlpuzzle.customsql('AVG("custom") AS "x"')
    columns.columns(customsql, 'id')
    assert str(columns) == 'AVG("custom") AS "x", "id"'
Example #6
0
 def test_custom_in_column_with_as(self):
     self.columns.columns({sqlpuzzle.customsql('AVG("custom")'): 'x'})
     self.assertEqual(str(self.columns), 'AVG("custom") AS "x"')
def test_copy_with_custom():
    query1 = sqlpuzzle.select_from('t').where(sqlpuzzle.customsql('x'))
    query2 = query1.copy()
    assert str(query1) == str(query2)
Example #8
0
def test_custom_one_table(tables):
    customsql = sqlpuzzle.customsql('"custom" JOIN "sql"')
    tables.set(customsql)
    assert str(tables) == '"custom" JOIN "sql"'
Example #9
0
 def test_customsql(self):
     self.tables.set('t')
     self.tables.join('u').on('col', sqlpuzzle.customsql('x'))
     self.assertEqual(str(self.tables), '"t" JOIN "u" ON "col" = x')
Example #10
0
 def test_custom_in_column_with_as(self):
     self.tables.set({sqlpuzzle.customsql('"custom"'): 'x'})
     self.assertEqual(str(self.tables), '"custom" AS "x"')
Example #11
0
 def test_custom_in_column_with_as(self):
     self.columns.columns({sqlpuzzle.customsql('AVG("custom")'): 'x'})
     self.assertEqual(str(self.columns), 'AVG("custom") AS "x"')
Example #12
0
 def setUp(self):
     super(CustomSqlTest, self).setUp()
     self.customsql = sqlpuzzle.customsql('AVG("custom") AS "x"')
Example #13
0
def test_custom_in_column_with_as(columns):
    columns.columns({sqlpuzzle.customsql('AVG("custom")'): 'x'})
    assert str(columns) == 'AVG("custom") AS "x"'
 def test_copy_with_custom(self):
     query1 = sqlpuzzle.select_from('t').where(sqlpuzzle.customsql('x'))
     query2 = query1.copy()
     self.assertEquals(str(query1), str(query2))
def test_compare_column_with_custom():
    custom = sqlpuzzle.customsql('custom')
    column = Column('column')
    assert column != custom  # Do not throw exception.
 def test_custom_sql(self):
     # Do not throw exception InvalidArgumentException.
     sqlpuzzle.relations.EQ(sqlpuzzle.customsql('custom'))
     sqlpuzzle.relations.NE(sqlpuzzle.customsql('custom'))
     sqlpuzzle.relations.GT(sqlpuzzle.customsql('custom'))
     sqlpuzzle.relations.GE(sqlpuzzle.customsql('custom'))
     sqlpuzzle.relations.LT(sqlpuzzle.customsql('custom'))
     sqlpuzzle.relations.LE(sqlpuzzle.customsql('custom'))
     sqlpuzzle.relations.LIKE(sqlpuzzle.customsql('custom'))
     sqlpuzzle.relations.REGEXP(sqlpuzzle.customsql('custom'))
     sqlpuzzle.relations.IN(sqlpuzzle.customsql('custom'))
     sqlpuzzle.relations.NOT_IN(sqlpuzzle.customsql('custom'))
     sqlpuzzle.relations.IS(sqlpuzzle.customsql('custom'))
     sqlpuzzle.relations.IS_NOT(sqlpuzzle.customsql('custom'))
Example #17
0
def test_custom_simple(values):
    customsql = sqlpuzzle.customsql('"age" = "age" + 1')
    values.set(customsql)
    assert str(values) == '"age" = "age" + 1'
Example #18
0
def test_custom_in_column_with_as(tables):
    tables.set({sqlpuzzle.customsql('"custom"'): 'x'})
    assert str(tables) == '"custom" AS "x"'
Example #19
0
 def setUp(self):
     super(CustomSqlTest, self).setUp()
     self.customsql = sqlpuzzle.customsql('"age" = "age" + 1')
Example #20
0
 def setUp(self):
     super(CustomSqlTest, self).setUp()
     self.customsql = sqlpuzzle.customsql('AVG("custom") AS "x"')
Example #21
0
def test_custom_simple(where):
    customsql = sqlpuzzle.customsql('"custom" = "sql" OR "sql" = "custom"')
    where.where(customsql)
    assert str(where) == 'WHERE "custom" = "sql" OR "sql" = "custom"'
Example #22
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sqlpuzzle


avg = sqlpuzzle.customsql('AVG(`age`) AS "avgAge"')
table = sqlpuzzle.customsql('`user` LEFT JOIN `country` ON `user`.`country_id`=`country`.`id`')
where = sqlpuzzle.customsql('(`enable` = 1 OR `vip` = 1)')

sql = sqlpuzzle.select('country.name', avg).from_(table)
sql.where(where).where(planet='Earth')
sql.group_by('user.country_id')

print(sql)
#
# output:
# (for better reading splited to more lines)
#
# SELECT `country`.`name`, AVG(`age`) AS "avgAge"
# FROM `user` LEFT JOIN `country` ON `user`.`country_id`=`country`.`id`
# WHERE (`enable` = 1 OR `vip` = 1) AND `planet` = 'Earth'
# GROUP BY `user`.`country_id`
#


table = sqlpuzzle.customsql('`user`')
set_ = sqlpuzzle.customsql('`age` = `age` + 1')

sql = sqlpuzzle.update(table).set(set_).where(where)
print(sql)
Example #23
0
 def test_copy_with_custom(self):
     query1 = sqlpuzzle.select_from('t').where(sqlpuzzle.customsql('x'))
     query2 = query1.copy()
     self.assertEquals(str(query1), str(query2))
Example #24
0
 def test_customsql(self):
     self.tables.set('t')
     self.tables.join('u').on('col', sqlpuzzle.customsql('x'))
     self.assertEqual(str(self.tables), '"t" JOIN "u" ON "col" = x')
Example #25
0
 def test_compare_column_with_custom(self):
     custom = sqlpuzzle.customsql('custom')
     column = Column('column')
     self.assertFalse(column == custom)  # Do not throw exception.
Example #26
0
 def test_custom_in_column_with_as(self):
     self.tables.set({sqlpuzzle.customsql('"custom"'): 'x'})
     self.assertEqual(str(self.tables), '"custom" AS "x"')
Example #27
0
 def test_custom_sql(self):
     # Do not throw exception InvalidArgumentException.
     sqlpuzzle.relations.EQ(sqlpuzzle.customsql('custom'))
     sqlpuzzle.relations.NE(sqlpuzzle.customsql('custom'))
     sqlpuzzle.relations.GT(sqlpuzzle.customsql('custom'))
     sqlpuzzle.relations.GE(sqlpuzzle.customsql('custom'))
     sqlpuzzle.relations.LT(sqlpuzzle.customsql('custom'))
     sqlpuzzle.relations.LE(sqlpuzzle.customsql('custom'))
     sqlpuzzle.relations.LIKE(sqlpuzzle.customsql('custom'))
     sqlpuzzle.relations.REGEXP(sqlpuzzle.customsql('custom'))
     sqlpuzzle.relations.IN(sqlpuzzle.customsql('custom'))
     sqlpuzzle.relations.NOT_IN(sqlpuzzle.customsql('custom'))
     sqlpuzzle.relations.IS(sqlpuzzle.customsql('custom'))
     sqlpuzzle.relations.IS_NOT(sqlpuzzle.customsql('custom'))
Example #28
0
def test_custom_one_table(tables):
    customsql = sqlpuzzle.customsql('"custom" JOIN "sql"')
    tables.set(customsql)
    assert str(tables) == '"custom" JOIN "sql"'
Example #29
0
 def setUp(self):
     super(CustomSqlTest, self).setUp()
     self.customsql = sqlpuzzle.customsql('"custom" = "sql" OR "sql" = "custom"')
Example #30
0
def test_custom_in_column_with_as(tables):
    tables.set({sqlpuzzle.customsql('"custom"'): 'x'})
    assert str(tables) == '"custom" AS "x"'
Example #31
0
def test_customsql_compare_to_str():
    assert sqlpuzzle.customsql('avg(col)') == 'avg(col)'
    assert sqlpuzzle.customsql('avg(col)') == sqlpuzzle.customsql('avg(col)')
    assert sqlpuzzle.customsql('avg(col)') != 'foo'
 def test_compare_column_with_custom(self):
     custom = sqlpuzzle.customsql('custom')
     column = Column('column')
     self.assertFalse(column == custom)  # Do not throw exception.
Example #33
0
def test_customsql_as_key_in_dict():
    custom = sqlpuzzle.customsql('avg(col)')
    sql = sqlpuzzle.select({
        custom: 'acol',
    }).from_('table')
    assert str(sql) == 'SELECT avg(col) AS "acol" FROM "table"'
Example #34
0
 def test_customsql(self, tables):
     tables.set('t')
     tables.join('u').on('col', sqlpuzzle.customsql('x'))
     assert str(tables) == '"t" JOIN "u" ON "col" = x'
def test_copy_with_custom():
    query1 = sqlpuzzle.select_from('t').where(sqlpuzzle.customsql('x'))
    query2 = query1.copy()
    assert str(query1) == str(query2)
Example #36
0
def test_custom_more_tables(tables):
    customsql = sqlpuzzle.customsql('"custom" JOIN "sql"')
    tables.set(customsql, 'id')
    assert str(tables) == '"custom" JOIN "sql", "id"'
def test_compare_column_with_custom():
    custom = sqlpuzzle.customsql('custom')
    column = Column('column')
    assert column != custom  # Do not throw exception.
Example #38
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sqlpuzzle

avg = sqlpuzzle.customsql('AVG(`age`) AS "avgAge"')
table = sqlpuzzle.customsql(
    '`user` LEFT JOIN `country` ON `user`.`country_id`=`country`.`id`')
where = sqlpuzzle.customsql('(`enable` = 1 OR `vip` = 1)')

sql = sqlpuzzle.select('country.name', avg).from_(table)
sql.where(where).where(planet='Earth')
sql.group_by('user.country_id')

print(sql)
#
# output:
# (for better reading splited to more lines)
#
# SELECT `country`.`name`, AVG(`age`) AS "avgAge"
# FROM `user` LEFT JOIN `country` ON `user`.`country_id`=`country`.`id`
# WHERE (`enable` = 1 OR `vip` = 1) AND `planet` = 'Earth'
# GROUP BY `user`.`country_id`
#

table = sqlpuzzle.customsql('`user`')
set_ = sqlpuzzle.customsql('`age` = `age` + 1')

sql = sqlpuzzle.update(table).set(set_).where(where)
print(sql)
# output:
Example #39
0
def test_custom_one_column(columns):
    customsql = sqlpuzzle.customsql('AVG("custom") AS "x"')
    columns.columns(customsql)
    assert str(columns) == 'AVG("custom") AS "x"'