def test_unique_params_only(self): metadata = MetaData() table = Table( 'table', metadata, Column('id', Integer, primary_key=True), Column('name', Unicode(16), nullable=False, unique=True), ) clause = ConditionalInsert(table, {table.c.name: 'asdf'}) # there is a bug in upstream in pylint so we have to disable it for # SQLAlchemy 0.9. # https://bitbucket.org/logilab/astroid/issue/39/support-for-sqlalchemy #pylint: disable=E1120 compiled = clause.compile(dialect=MySQLDialect()) self.assertEquals( str(compiled), 'INSERT INTO `table` (name)\n' 'SELECT %s\n' 'FROM DUAL\n' 'WHERE NOT (EXISTS (SELECT 1 \n' 'FROM `table` \n' 'WHERE `table`.name = %s FOR UPDATE))') self.assertEquals(compiled.positiontup, ['name', 'name_1']) self.assertEquals(compiled.params, {'name': 'asdf', 'name_1': 'asdf'}) #pylint: disable=E1120 compiled = clause.compile(dialect=SQLiteDialect()) self.assertEquals( str(compiled), 'INSERT INTO "table" (name)\n' 'SELECT ?\n' 'WHERE NOT (EXISTS (SELECT 1 \n' 'FROM "table" \n' 'WHERE "table".name = ?))') self.assertEquals(compiled.positiontup, ['name', 'name_1']) self.assertEquals(compiled.params, {'name': 'asdf', 'name_1': 'asdf'})
def test_with_extra_params(self): metadata = MetaData() table = Table('table', metadata, Column('id', Integer, primary_key=True), Column('name', Unicode(16), nullable=False, unique=True), Column('extra', Unicode(16), nullable=False), ) clause = ConditionalInsert(table, {table.c.name: 'asdf'}, {table.c.extra: 'something'}) #pylint: disable=E1120 compiled = clause.compile(dialect=MySQLDialect()) self.assertEquals(str(compiled), 'INSERT INTO `table` (name, extra)\n' 'SELECT %s, %s\n' 'FROM DUAL\n' 'WHERE NOT (EXISTS (SELECT 1 \n' 'FROM `table` \n' 'WHERE `table`.name = %s FOR UPDATE))') self.assertEquals(compiled.positiontup, ['name', 'extra', 'name_1']) self.assertEquals(compiled.params, {'name': 'asdf', 'extra': 'something', 'name_1': 'asdf'}) #pylint: disable=E1120 compiled = clause.compile(dialect=SQLiteDialect()) self.assertEquals(str(compiled), 'INSERT INTO "table" (name, extra)\n' 'SELECT ?, ?\n' 'WHERE NOT (EXISTS (SELECT 1 \n' 'FROM "table" \n' 'WHERE "table".name = ?))') self.assertEquals(compiled.positiontup, ['name', 'extra', 'name_1']) self.assertEquals(compiled.params, {'name': 'asdf', 'extra': 'something', 'name_1': 'asdf'})
def test_unique_params_only(self): metadata = MetaData() table = Table('table', metadata, Column('id', Integer, primary_key=True), Column('name', Unicode(16), nullable=False, unique=True), ) clause = ConditionalInsert(table, {table.c.name: 'asdf'}) # there is a bug in upstream in pylint so we have to disable it for # SQLAlchemy 0.9. # https://bitbucket.org/logilab/astroid/issue/39/support-for-sqlalchemy #pylint: disable=E1120 compiled = clause.compile(dialect=MySQLDialect()) self.assertEquals(str(compiled), 'INSERT INTO `table` (name)\n' 'SELECT %s\n' 'FROM DUAL\n' 'WHERE NOT (EXISTS (SELECT 1 \n' 'FROM `table` \n' 'WHERE `table`.name = %s FOR UPDATE))') self.assertEquals(compiled.positiontup, ['name', 'name_1']) self.assertEquals(compiled.params, {'name': 'asdf', 'name_1': 'asdf'}) #pylint: disable=E1120 compiled = clause.compile(dialect=SQLiteDialect()) self.assertEquals(str(compiled), 'INSERT INTO "table" (name)\n' 'SELECT ?\n' 'WHERE NOT (EXISTS (SELECT 1 \n' 'FROM "table" \n' 'WHERE "table".name = ?))') self.assertEquals(compiled.positiontup, ['name', 'name_1']) self.assertEquals(compiled.params, {'name': 'asdf', 'name_1': 'asdf'})
def test_unique_params_only(self): metadata = MetaData() table = Table('table', metadata, Column('id', Integer, primary_key=True), Column('name', Unicode(16), nullable=False, unique=True), ) clause = ConditionalInsert(table, {table.c.name: 'asdf'}) compiled = clause.compile() self.assertEquals(str(compiled), 'INSERT INTO "table" ("table".name)\n' 'SELECT :name\nFROM DUAL\nWHERE NOT EXISTS ' '(SELECT 1 FROM "table"\nWHERE "table".name = :name_1 FOR UPDATE)') self.assertEquals(compiled.params, {'name': 'asdf', 'name_1': 'asdf'})
def test_with_extra_params(self): metadata = MetaData() table = Table('table', metadata, Column('id', Integer, primary_key=True), Column('name', Unicode(16), nullable=False, unique=True), Column('extra', Unicode(16), nullable=False), ) clause = ConditionalInsert(table, {table.c.name: 'asdf'}, {table.c.extra: 'something'}) #pylint: disable=E1120 compiled = clause.compile() self.assertEquals(str(compiled), 'INSERT INTO "table" ("table".name, "table".extra)\n' 'SELECT :name, :extra\nFROM DUAL\nWHERE NOT EXISTS ' '(SELECT 1 FROM "table"\nWHERE "table".name = :name_1 FOR UPDATE)') self.assertEquals(compiled.params, {'name': 'asdf', 'extra': 'something', 'name_1': 'asdf'})
def test_unique_params_only(self): metadata = MetaData() table = Table('table', metadata, Column('id', Integer, primary_key=True), Column('name', Unicode(16), nullable=False, unique=True), ) clause = ConditionalInsert(table, {table.c.name: 'asdf'}) # there is a bug in upstream in pylint so we have to disable it for # SQLAlchemy 0.9. # https://bitbucket.org/logilab/astroid/issue/39/support-for-sqlalchemy #pylint: disable=E1120 compiled = clause.compile() self.assertEquals(str(compiled), 'INSERT INTO "table" ("table".name)\n' 'SELECT :name\nFROM DUAL\nWHERE NOT EXISTS ' '(SELECT 1 FROM "table"\nWHERE "table".name = :name_1 FOR UPDATE)') self.assertEquals(compiled.params, {'name': 'asdf', 'name_1': 'asdf'})
def test_unique_params_only(self): metadata = MetaData() table = Table( 'table', metadata, Column('id', Integer, primary_key=True), Column('name', Unicode(16), nullable=False, unique=True), ) clause = ConditionalInsert(table, {table.c.name: 'asdf'}) # there is a bug in upstream in pylint so we have to disable it for # SQLAlchemy 0.9. # https://bitbucket.org/logilab/astroid/issue/39/support-for-sqlalchemy #pylint: disable=E1120 compiled = clause.compile() self.assertEquals( str(compiled), 'INSERT INTO "table" ("table".name)\n' 'SELECT :name\nFROM DUAL\nWHERE NOT EXISTS ' '(SELECT 1 FROM "table"\nWHERE "table".name = :name_1 FOR UPDATE)') self.assertEquals(compiled.params, {'name': 'asdf', 'name_1': 'asdf'})
def test_with_extra_params(self): metadata = MetaData() table = Table( 'table', metadata, Column('id', Integer, primary_key=True), Column('name', Unicode(16), nullable=False, unique=True), Column('extra', Unicode(16), nullable=False), ) clause = ConditionalInsert(table, {table.c.name: 'asdf'}, {table.c.extra: 'something'}) #pylint: disable=E1120 compiled = clause.compile() self.assertEquals( str(compiled), 'INSERT INTO "table" ("table".name, "table".extra)\n' 'SELECT :name, :extra\nFROM DUAL\nWHERE NOT EXISTS ' '(SELECT 1 FROM "table"\nWHERE "table".name = :name_1 FOR UPDATE)') self.assertEquals(compiled.params, { 'name': 'asdf', 'extra': 'something', 'name_1': 'asdf' })