How to keep Powerbuilder from prepending table owner to table name (Postgres / PB 10.5) - postgresql

I am connecting to a Postgresql database from Power Builder 10.5, using ODBC on Windows 7.. and I notice that PB prepends the table owner to the table name, eg if I am connected to the database as "user", it will format the query as "SELECT x, y, z FROM user.tablename".
This makes sense in Sybase, but does not work correctly in postgres, where schemas and users are a separate thing.
I tested by creating a postgres schema with the same name as the user, and then putting the tables within the schema. So, when PB used "username.tablename" postgres interpreted it as "schemaname.tablename" and this worked.. but it was just a test and not a useable solution.
It says in the docs that if the table owner is the same as the current user, PB will not prepend the owner, but if they don't match, it will. But in my test program, I see is the opposite: If UID is the same as the owner name, it DOES prepend, if they don't match, it doesn't.
Here's my connect code:
sqlca.DBMS = "ODBC"
sqlca.userid = "pblearn"
sqlca.dbpass = "pblearn"
string ls_DSN = "PBLEARN"
string ls_connect = "ConnectString='"
ls_connect += "DSN=" + ls_DSN + ";"
ls_connect += "UID=" + sqlca.userid + ";"
ls_connect += "PWD=" + sqlca.dbpass + "'"
sqlca.dbparm = ls_connect + ", SQLQualifiers=0"
connect;
My schemas are pblearn and public (default).. and two users "pblearn" and "pblearn2". If I connect with pblearn, prepend happens and I see the tables in pblearn (owner of the tables) schema, if I use pblearn2, the username is not prepended and I see the tables in public schema.
How can I get PB to either not prepend the username, or to prepend a consistent schema name regardless of user?
Thanks

In your database section of the PBODB105.INI used by your installation, add the following property :
PBTableOwner='NO'
From the documentation :
;PBTableOwner='NO' - do not qualify table names, default is 'YES'
EDIT :
If no sections exist for a particular connection then Powerbuilder
runs as an ODBC compliant client and extensions that might be
available cannot not be utilized. The search algorithm for the
entries is:
IF section and entry for are present current datasource
THEN use entry value
ELSE IF section corresponding to DBMS_Name Driver_Name exist
THEN use entry value if it exist
ELSE IF section corresponding to DBMS_Name exist
THEN use entry value if it exist
SECTION Headings
DataSource_Name (None are in ini file by default but if you need to override the more general setting of DBMS_Driver or DBMS_Name you would put in a data source specific section
DBMS_Name Driver_Name (Driver_Name is stripped of .dll extension)
DBMS_Name (DBMS name returned by the SQLGetInfo call)
So the easiest way to add a section for your Postgres installation is to make a section named with your current datasource name or if you prefer to use the DBMS_NAME then check this example : http://www.rgagnon.com/pbdetails/pb-0061.html to see the DBMS name returned by the ODBC driver.

Related

Loopback (DB2) - Can not create an instance of PersistedModel that uses a schema other than the userid

I am trying to define a model that is based on the PersistedModel to access a table in DB2, call it MY_SCHEMA.MY_TABLE.
I created the model MY_TABLE, based on PersistedModel, with a Data Source (datasources.json) where the definition includes the attribute "schema": "MY_SCHEMA". The data source also contains the userid my_userid, used for the connection.
Current Behavior
When I try to call the API for this model, it tries to access the table my_userid.MY_TABLE.
Expected Behavior
It should access MY_SCHEMA.MY_TABLE.
The DB2 instance happens to be on a System Z. I have created a table called my_userid.MY_TABLE and that will work, however for the solution we are trying to build, there are multiple schemas required.
Note that this only appears to be an issue with Db2 on System Z. I can change schemas on Db2 LUW.
What LoopBack connector are you using? What version? Can you also check what version of loopback-ibmdb is installed in your node_modules folder?
AFAICT, LoopBack's DB2-related connectors support schema field, see https://github.com/strongloop/loopback-ibmdb/blob/master/lib/ibmdb.js#L96-L100
self.schema = this.username;
if (settings.schema) {
self.schema = settings.schema.toUpperCase();
}
self.connStr += ';CurrentSchema=' + self.schema;
Have you considered configuring the database connection using DSN instead of individual fields like hostname and username?
In your datasource config JSON:
"dsn": "DATABASE={dbname};HOSTNAME={hostname};UID={username};PWD={password};CurrentSchema=MY_SCHEMA"

matlab error when connecting to postgresql database

I'm trying to connec to a PostgreSQL database with following command:
connection = database( ...
options.getDatabaseName(), ...
options.getUsername(), ...
options.getPassword(), ...
"org.postgresql.Driver", ...
"jdbc:postgresql://" + options.getHostname() + ":" + options.getPort() + "/" + options.getDatabaseName() ...
);
It returns me following error:
Error using database (line 59)
Unmatched parameter name 'org.postgresql.Driver' must be a string scalar or character vector that can represent a field name.
I've seen other questions about that, like this one but the error message is different.
What I'm doing wrong?
I've found the solution by myself, and it's tricky (maybe related to a bug in my opinion).
In order to test the database connection I've created first a connection with the Database explorer. It worked, and I saved this connection using the same name of the database.
When I use the database command, by inspecting it source code I've seen that the first thing that it does it to check if there's an existing data source with that name and, if not, it search for the database. The problem was that since my connection had the same database name, database supposed that I wanted to use the data source command version instead of the database. It tried to use this command:
conn = database(datasource,username,password)
instead of this one:
conn = database(databasename,username,password,driver,url)
since wtrade is both name of the database and of the data source. In that case the fourth argument, driver, must be a parameter name, like "Vendor" of "PortNumber", as per Matlab documentation, so since the driver string does not match a parameter name, I had the error.
I've removed the datasource with the same name of the database and everything started to work.
I've notified this to MathWorks, since in my opinion there should be no problem if a database has the same name of a datasource, since the signature are different, so database command should handle also this case.

How does one prevent MS Access from concatenating the schema and table names thereby taking them over the 64 character limit?

I have been trying to get around this for several day's now with no luck. I loaded Libre Office to see how that would handle it, and its native support for PostgeSQL works wonderfully and I can see the true data structure. Which is how I found out I was dealing with more than one table. What I am seeing in MS Access is the two names concatenated together. The concatenation takes them over the 64 character limit that appears to be built into the ODBC driver. I have seen many references to modifying namedatalen on the server side, but my problem is on the ODBC side. Most of the tables are under the 64 character limit even with the concatenation and work fine. As such I know everything else is working. The specific error I am getting is
'your_extra_long_schema_name_your_table_name_that_you_want_to_get_data_from'
is not a valid name. Make sure it does not include invalid characters
or punctuation and that it is not too long.
Object names in an Access database are limited to 64 characters (ref: here). When creating an ODBC linked table in the Access UI the default behaviour is to concatenate the schema name and table name with an underscore and use that as the linked table name so, for example, the remote table table1 in the schema public would produce a linked table in Access named public_table1. If such a name exceeds 64 characters then Access will throw an error.
However, we can use VBA to create the table link with a shorter name, like so:
Option Compare Database
Option Explicit
Sub so38999346()
DoCmd.TransferDatabase acLink, "ODBC Database", "ODBC;DSN=PostgreSQL35W", acTable, _
"public.hodor_hodor_hodor_hodor_hodor_hodor_hodor_hodor_hodor_hodor", _
"hodor_linked_table"
End Sub
(Tested with Access 2010.)

mysql import sql file without overwrite but update curent value + backup value

I have a 2 databases
1.db_temporary
2.db_primary
in db_temporary I have a table which contain bunch of data that I want to keep without overwrite it but update it from imported MYSQL file
I dump db_primary and import backup to db_temporary with this command
D:\mysql4.0.27\bin\mysqldump.exe --add-drop-table db_primary tb_wantomodify > "backupfile.sql"
D:\mysql4.0.27\bin\mysql.exe db_temporary < "backupfile.sql"
I have tried This Solution yeah it not overwrited , but what I want is update (addition) recent field of db_temporary with new value of backup.
Technicaly similiar to update set curvalue=curvalue+ 'newvaluefrombackup' like
Is it possible todo this?
Thank You
Firstly you can put both of those tables in the same database. There's no reason to create two seperate files. Secondly what you want here is the SQL UPDATE command. First create a database object and set it to your database.
SQLiteDatabase dataBase = SQLiteDatabase.openDatabase(myPath,
null, SQLiteDatabase.OPEN_READWRITE);
database.execSQL("UPDATE " +yourTableNameHere+ " SET " +theColumnYouWantToUpdate+ "='" +theNewValue+ "' WHERE " +theColumnNametoUpdate+ "='" +theNewValue+ "'");
This may seem confusing at first but what you need to understand is that SQL commands read as strings. This example assumes you're using String constants for your table data, as you should. The + sign before and after is a concatenation command. Make sure you add spaces. And don't forget the commas after the values you want checked. There's a pretty good SQL commands tutorial here: [http://www.1keydata.com/sql/sqlselect.html]

T-SQL 2000: Four part table name

I don't usually work with linked servers, and so I'm not sure what I'm doing wrong here.
A query like this will work to a linked foxpro server from sql 2000:
EXEC('Select * from openquery(linkedServer, ''select * from linkedTable'')')
However, from researching on the internet, something like this should also work:
Select * from linkedserver...linkedtable
but I receive this error:
Server: Msg 7313, Level 16, State 1, Line 1
Invalid schema or catalog specified for provider 'MSDASQL'.
OLE DB error trace [Non-interface error: Invalid schema or catalog specified for the provider.].
I realize it's supposed to be ServerAlias.Category.Schema.TableName, but if I run sp_ tables _ex on the linked server, for the category for all tables I just get the network path to where the data files are, and the schema is null.
Is this server setup incorrectly? Or is what I'm trying to do not possible?
From MSDN:
Always use fully qualified names when
working with objects on linked
servers. There is no support for
implicit resolution to the dbo owner
name for tables in linked servers
You cannot rely on the implicit schema name resolution of the '..' notation for linked servers. For a FoxPro 'server' you're going to have to use the database and schema as they map to their FoxPro counterparts in the driver you use (I think they map to folder and file name, but I have't use a ISAM file driver in more than 10 years now).
I think you need to be explicit about resources in the linked server part of the query, for example:
EXEC SomeLinkedServer.Database.dbo.SomeStoredProc
In other words just dotting them out doesn't work in this case, you have to be more specific.
It's actually:
ServerAlias.Catalog.Schema.LinkedTable
Catalog is the database that you're querying on the linked server, and catalog is the catalog of the remote table. So a valid four-part name would look lik this
ServerAlias.AdventureWorks.HumanResources.Employee
or
ServerAlias.MyDB.dbo.MyTable