def test_simple(self): sql, bind_vars = sql_builder.insert_query( table_name='my_table', columns=['col_a', 'col_b'], col_a=1, col_b=2) self.assertEqual( sql, 'INSERT INTO my_table (col_a, col_b) VALUES (%(col_a)s, %(col_b)s)') self.assertEqual(bind_vars, dict(col_a=1, col_b=2))
def insert_primary(class_, cursor, **bind_vars): if class_.columns_list is None: raise dbexceptions.ProgrammingError("DB class should define columns_list") query, bind_vars = sql_builder.insert_query(class_.table_name, class_.columns_list, **bind_vars) cursor.execute(query, bind_vars) return cursor.lastrowid
def insert(class_, cursor, **bind_vars): if class_.columns_list is None: raise dbexceptions.ProgrammingError("DB class should define columns_list") query, bind_vars = sql_builder.insert_query(class_.table_name, class_.columns_list, **bind_vars) cursor.execute(query, bind_vars) return cursor.lastrowid
def insert(class_, cursor, **bind_vars): if class_.columns_list is None: raise dbexceptions.ProgrammingError("DB class should define columns_list") keyspace_id = bind_vars.get('keyspace_id', None) if keyspace_id is None: kid = cursor.keyspace_ids[0] keyspace_id = unpack_keyspace_id(kid) bind_vars['keyspace_id'] = keyspace_id query, bind_vars = sql_builder.insert_query(class_.table_name, class_.columns_list, **bind_vars) cursor.execute(query, bind_vars) return cursor.lastrowid
def insert(class_, cursor, **bind_vars): if class_.columns_list is None: raise dbexceptions.ProgrammingError( "DB class should define columns_list") keyspace_id = bind_vars.get('keyspace_id', None) if keyspace_id is None: kid = cursor.keyspace_ids[0] keyspace_id = unpack_keyspace_id(kid) bind_vars['keyspace_id'] = keyspace_id query, bind_vars = sql_builder.insert_query(class_.table_name, class_.columns_list, **bind_vars) cursor.execute(query, bind_vars) return cursor.lastrowid
def create_insert_query(class_, **bind_vars): class_._validate_column_value_pairs_for_write(**bind_vars) return sql_builder.insert_query(class_.table_name, class_.columns_list, **bind_vars)
def create_insert_query(class_, **bind_vars): return sql_builder.insert_query(class_.table_name, class_.columns_list, **bind_vars)
def test_simple(self): sql, bind_vars = sql_builder.insert_query(table_name="my_table", columns=["col_a", "col_b"], col_a=1, col_b=2) self.assertEqual(sql, "INSERT INTO my_table (col_a, col_b) VALUES (%(col_a)s, %(col_b)s)") self.assertEqual(bind_vars, dict(col_a=1, col_b=2))