By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,287 Members | 1,287 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,287 IT Pros & Developers. It's quick & easy.

Set Schema programmatically?

P: 4
Is there any way to set the "current schema" programmatically (C++, if it matters)? I've tried both "SQL_ATTR_CLISCHEMA" and "SQL_ATTR_CURRENT_SCHEMA" via "SQLSetConnectAttr()" to no avail (I've verified that the chosen schema was properly set via "SQLGetConnectAttr"() as well). The schema would "set", but it never seemed to affect any queies (I set it to something invalid, but could still query the tables as if the schema was correct).

I could prepend the schema name to every table reference in every SQL statement in our application, but obviously, I'd prefer to avoid that.

It seems that the schema name is the same as the user name, and I'd like to be able to change that within the application, but nothing seems to affect it.

Just to be clear, I'm looking for a way to perform "set schema XXX" from within our application.

Thanks very much for your time and any info...
Feb 1 '07 #1
Share this Question
Share on Google+
3 Replies

P: 6
Your guess is right. Execute this SQL statement before any others:

set schema XXXXXX, where XXXXX is the schema name.

However, if the new schema and the old schema have objects of the same name, it will take the original schema as default. So prefixing the object name in SQL statement should be a better approach actually.

Feb 2 '07 #2

P: 4
Thanks for the reply, but I can't find the equivalent function call for "set schema XXX". The "set schema" command is a command-line way of doing it - I need a way of doing it from within our application (I think DB2 calls it a CLI (Call level interface)). I.E.: Something along the lines of SQLSetConnectAttr(), but which affects the current schema.

Feb 2 '07 #3

P: 4
bump. Any ideas, anyone?

Mar 9 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.