Skip to content

Connection.set_current_schema() fails #5

@davis-junior

Description

@davis-junior

Using ibm-db 2.0.5.9 from IBM i repo.

Connection.set_current_schema() fails with exception:

Statement Execute Failed: Variable HVR0001 not character, UCS-2 graphic, or UTF-16 graphic. SQLSTATE=42618 SQLCODE=-5024

Internally, it executes the prepared statement "set current schema = ?" with proper parameter, and that's where the exception is thrown. A workaround is to concatenate directly (improper).

Here's a few tests, just change "schema" to an existing one on the system. The first three fail with the above exception.

import unittest
import ibm_db
import ibm_db_dbi


class IBMDBTest(unittest.TestCase):
    schema = 'put_schema_here'

    def test_set_current_schema(self):
        '''Tests Connection.set_current_schema()
        '''
        conn = ibm_db_dbi.connect('DATABASE=*LOCAL')
        conn.set_current_schema(self.schema)
        self.assertEqual(conn.get_current_schema(), self.schema, 'Schema should be ' + self.schema)
        conn.close()
        
    def test_set_current_schema2(self):
        '''Tests Cursor execution of proper prepared statement
        '''
        conn = ibm_db_dbi.connect('DATABASE=*LOCAL')
        curs = conn.cursor()
        curs.execute("set current schema = ?", (self.schema,))
        self.assertEqual(conn.get_current_schema(), self.schema, 'Schema should be ' + self.schema)
        conn.close()
        
    def test_set_current_schema3(self):
        '''Tests direct driver execution using proper prepared statement form
        '''
        conn = ibm_db_dbi.connect('DATABASE=*LOCAL')
        stmt = ibm_db.prepare(conn.conn_handler, "set current schema = ?")
        ibm_db.execute(stmt, (self.schema,))
        self.assertEqual(conn.get_current_schema(), self.schema, 'Schema should be ' + self.schema)
        conn.close()
        
    def test_set_current_schema4(self):
        '''Tests direct driver execution using concatenated parameters
        '''
        conn = ibm_db_dbi.connect('DATABASE=*LOCAL')
        stmt = ibm_db.prepare(conn.conn_handler, "set current schema = '" + self.schema + "'")
        ibm_db.execute(stmt)
        self.assertEqual(conn.get_current_schema(), self.schema, 'Schema should be ' + self.schema)
        conn.close()
        
if __name__ == "__main__":
    unittest.main()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions