DBI: are schema and table-name enough for a qualified table name? - perl

Are there cases where a qualified table name consisting of schema and table-name, is not sufficient if the connection was made with the DBI connect method?
Not sufficient in the sense that the catalog in the qualified table name would also be required.
Connect could look like this:
my $dbh = DBI->connect( "dbi:$sdriver:$db", ... );
my $dbh = DBI->connect( "dbi:$sdriver:dbname=$db", ... );
The '...' could be one or more of: host, port, user, password and attributes.
For these drivers: DBD::SQLite, DBD::mysql, DBD::MariaDB, DBD::Pg, DBD::Firebird, DBD::DB2 and DBD::Informix.
It is used in App::DBBrowser.

Related

PostgresSQL: org.postgresql.util.PSQLException: ERROR: Unsupported startup parameter: search_path

When I try to connect to the database on postgres via jdbc, I get the following error:
org.postgresql.util.PSQLException: ERROR: Unsupported startup parameter: search_path
This is how I create the connection:
val connection = DriverManager.getConnection(profile.connection + Option(profile.catalog).getOrElse("")+ "?currentSchema="+Option(profile.schema).getOrElse(""),
profile.user, profile.password)
I use scala and a custom version of postgres.
pgbauncer
In short, pgbouncer at least my version does not work with the search_path parameter, this discussion led me to this idea. There are two ways to fix this problem:
Change the pgbouncer config file by adding
IGNORE_STARTUP_PARAMETERS: search_path
Make a connection without using the currentSchema parameter in the connection string and create connection like this:
val connection =
DriverManager.getConnection(
profile.connection + Option(profile.catalog).getOrElse(""),
profile.user, profile.password)
Then he will choose the scheme according to the rule set, in search_path, they usually set something like "$user", public, in this case, when connecting, he first tries to choose the same scheme as the user name, and if he does not find such a scheme, he chooses public.

Eloquent innodb - SQLSTATE[42S02]: Base table or view not found Table doesn't exist

I have this weird crash and trying for few hours to solve with no success, check everywhere on the internet and didn't find a solution.
I am running Eloquent (without laravel). I have two servers (frontend and backend). The DB is in the backend server.
I am running the exact same code to connect to the database using laravel from both servers. From the backend server everything works. In the frontend server, I get mixed result. Out of 9 tables:
three works, and I am able to retrieve the data.
three return [items:protected] => Array (), while table has data to return.
three cause fatal error SQLSTATE[42S02]: Base table or view not found Table doesn't exist
from #1 I understand that this is not related to issue with database user/password.
for #2, I checked the queries using getQueryLog(), and I run the queries in phpmyadmin, and they work.
from what I observed so far, all the tables that cause #3 are all InnoDB. Why my other tables are MyIsam I don't know.
And the exact same code works in the backend server, so it is not an issue with tables names are in singular or some other code related issue.
backend server is php 5.5.9, eloquent 5.4.45
frontend server is php 5.6.32, eloquent 5.4.36
Any idea what to do about #2 (return data empty) and #3 (php fatal error)?
Ok, found this crazy bug(s).
First, I found out that we had an old version of the database on the frontend server. It was not supposed to be there, so I didn't even think about it as a possibility.
In addition, there was a problem in the code:
$dbhost = __MYSQLDB_HOST__;
$dbuser = 'xxxxx';
$dbpass = 'xxxxx';
$dbname = 'xxxxx';
$capsule = new Capsule;
$capsule->addConnection(array(
'driver' => 'mysql',
'host' => 'localhost', // <= this is the problem!!!
'database' => $dbname,
'username' => $dbuser,
'password' => $dbpass,
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => ''
));
As you can see, when connecting to the database it used localhost instead of the $dbhost variable which contained the remote database host on the backend server.

Database connection with Firebird Adapter in Zend Framework

I just started to learn about ZF and Firebird because of a project I am assigned to. I have been trying to make the connection between both for several days now, but I haven't succeed yet.
I tried ZF with PDO_Mysql and it works just fine as it does Firebird connection with PHP (out of ZF), but when I try to make the connection with the Firebird adapter in ZF it keeps displaying all kinds of errors.
So, just to check. To make the connection in ZF with Firebird it should be done with the the adapter (Firebird.php) which I have configure in application.ini? I have something like this in the application.ini:
**resources.db.adapter = "Firebird"
resources.db.params.host = "localhost"
resources.db.params.dbname = "C:/wamp/www/WebTH/application/data/THDATA.gdb"
resources.db.params.username = "sysdba"
resources.db.params.password = "masterkey"**
Resulting error: ...Firebird.php): failed to open stream: No such file or directory in ...\Loader.php
I have also seen that a function needs to be added in the Bootstrap.php. If I add the function initDb in the bootstrap.php like this:
**protected function _initDb()
{
$this->bootstrap('config');
$config = $this->getResource('config');
$db = Zend_Db::factory('Firebird', array(
'host' => $config->Database->Server,
'username' => $config->Database->Username,
'password' => $config->Database->Password,
'dbname' => $config->Database->DBName,
'adapterNamespace' => 'ZendX_Db_Adapter'
));
return $db;
}**
I get the error: ...Uncaught exception 'Zend_Application_Bootstrap_Exception' with message 'Resource matching "config" not found' in ...\BootstrapAbstract.php
I would like to know what do I really need to do in order to make the connection work. Sorry if this is too obvious, but I haven't been able to find a basic connection case specific for Zend Framework and Firebird, therefore I am not really sure on what I should do and where I should go.
[Disclosure: I've never used the Firebird db.]
As you are probably aware, the Firebird adapter does not ship as part of the core ZF1 package. Looks like you can pull it from extras under the ZendX prefix:
http://framework.zend.com/svn/framework/extras/trunk/library/ZendX/Db/Adapter/
Drop the Firebird.php and Firebird/ files into a directory library/ZendX/Db/Adapter/.
If your application.ini uses the resources.db.* keys, then there is no need for an _initDb() method in your Bootstrap class. Just make sure that you include the adapterNamespace key in there, as well:
resources.db.params.adapterNamespace = "ZendX_Db_Adapter_"
You might also need to add the ZendX prefix to your autoloader namespaces:
autoloaderNamespaces[] = "ZendX_"
Not tested, but something like this should work.

Why is Perl's DBI failing to connect to my cataloged DB2 database?

I've downloaded the IBM DBI package, including all the packages in my program as specified in the docs. I've cataloged the DB and can connect to it from the command line, but my DBI connect fails:
$dbh = DBI->connect ("dbi:DB2:warehou1", user, pass) or die "Can't connect to sample database: $DBI::errstr";
Can't connect to sample database: [IBM][CLI Driver] SQL1031N The database directory cannot be found on the indicated file system. SQLSTATE=58031
Consider using the full connection string when DBI can't resolve a simple database name:
my $string = "dbi:DB2:DATABASE=$db; HOSTNAME=$hostname; PORT=$port; PROTOCOL=TCPIP; UID=$user; PWD=$pass;";
my $dbh = DBI->connect($string, $user, $pass) || die "Connection failed with error: $DBI::errstr";

Check ip and dns name

T-sql
Is it possible to check if ip-address and dns name is the same ?
Resolving the hostname to an IP address is something that can be easily done within a CLR stored procedure.
If you are new to CLR, you may want to start from the following articles:
Writing Your First CLR Stored Procedure
MSDN - Introduction to SQL Server CLR Integration
As for the code to resolve the hostname, this can be easily done in C# as follows:
string hostname = "stackoverflow.com";
IPAddress[] ipList = Dns.GetHostAddresses(hostname);
foreach (IPAddress ip in ipList)
{
// ... check each ip with an IP address you pass
// as a parameter.
}
If you are wondering why you receive a list of IP addresses, you may be interested in checking out the following Stack Overflow post:
Dns.GetHostEntry returns multiple IP addresses
HOST_NAME() returns the client's computer name.
This code resolves its ip address using ping and xp_cmdshell:
set nocount on
declare #ip varchar(255), #cmd varchar(100)
set #cmd = 'ping -n 1 ' + HOST_NAME()
create table #temptb (grabfield varchar(255))
insert into #temptb exec master.dbo.xp_cmdshell #cmd
select #ip = substring(grabfield, charindex('[',grabfield)+1,
charindex(']',grabfield)-charindex('[',grabfield)-1) from #temptb where left(grabfield,7) = 'Pinging'
print #ip
drop table #temptb
set nocount off
Source: http://www.sqlservercentral.com/Forums/Topic150196-8-1.aspx
you can use this query to get a lot of info about the connection:
SELECT
c.*,s.*
FROM sys.dm_exec_sessions s
INNER JOIN sys.dm_exec_connections c ON s.session_id=c.session_id
WHERE s.session_id = ##SPID
sys.dm_exec_connections.client_net_address = Host address of the client connecting to this server.
sys.dm_exec_connections.local_net_address = Represents the IP address on the server that this connection targeted. Available only for connections using the TCP transport provider.
you can try to see if there are duplicates IPs using a query like this:
SELECT
c.client_net_address, COUNT(*) AS CountOf
FROM sys.dm_exec_connections c
GROUP BY c.client_net_address
HAVING count(*)>1