mirror of
				https://github.com/MariaDB/server.git
				synced 2025-10-30 18:36:12 +01:00 
			
		
		
		
	 5cc2096f93
			
		
	
	
	5cc2096f93
	
	
	
		
			
			Perl DBD::MariaDB driver is available CPAN and is already used in production environment.
		
			
				
	
	
		
			66 lines
		
	
	
	
		
			1.6 KiB
		
	
	
	
		
			Perl
		
	
	
	
	
	
			
		
		
	
	
			66 lines
		
	
	
	
		
			1.6 KiB
		
	
	
	
		
			Perl
		
	
	
	
	
	
| 
 | |
| # vim:sw=2:ai
 | |
| 
 | |
| package hstest;
 | |
| 
 | |
| use DBI;
 | |
| use Net::HandlerSocket;
 | |
| 
 | |
| our %conf = ();
 | |
| 
 | |
| sub get_conf_env {
 | |
|   my ($key, $defval) = @_;
 | |
|   return $ENV{$key} || $defval;
 | |
| }
 | |
| 
 | |
| sub init_conf {
 | |
|   $conf{host} = get_conf_env("MYHOST", "localhost");
 | |
|   $conf{myport} = get_conf_env("MYPORT", 3306);
 | |
|   $conf{dbname} = get_conf_env("MYDBNAME", "hstestdb");
 | |
|   $conf{ssps} = get_conf_env("MYSSPS");
 | |
|   $conf{user} = get_conf_env("MYSQLUSER", "root");
 | |
|   $conf{pass} = get_conf_env("MYSQLPASS", "");
 | |
|   $conf{hsport} = get_conf_env("HSPORT", 9998);
 | |
|   $conf{hspass} = get_conf_env("HSPASS", undef);
 | |
| }
 | |
| 
 | |
| sub get_dbi_connection {
 | |
|   my ($dbname, $host, $myport, $ssps, $user, $pass)
 | |
|     = ($conf{dbname}, $conf{host}, $conf{myport}, $conf{ssps},
 | |
|       $conf{user}, $conf{pass});
 | |
|   my $mycnf = "binary_my.cnf";
 | |
|   my $dsn = "DBI:MariaDB:database=;host=$host;port=$myport"
 | |
|     . ";mariadb_server_prepare=$ssps"
 | |
|     . ";mariadb_read_default_group=perl"
 | |
|     . ";mariadb_read_default_file=../common/$mycnf";
 | |
|   my $dbh = DBI->connect($dsn, $user, $pass, { RaiseError => 1 });
 | |
|   return $dbh;
 | |
| }
 | |
| 
 | |
| sub init_testdb {
 | |
|   my $charset = $_[0] || "binary";
 | |
|   my $dbh = get_dbi_connection();
 | |
|   my $dbname = $conf{dbname};
 | |
|   $dbh->do("drop database if exists $dbname");
 | |
|   $dbh->do("create database $dbname default character set $charset");
 | |
|   $dbh->do("use $dbname");
 | |
|   return $dbh;
 | |
| }
 | |
| 
 | |
| sub get_hs_connection {
 | |
|   my ($host, $port) = @_;
 | |
|   $host ||= $conf{host};
 | |
|   $port ||= $conf{hsport};
 | |
|   my $hsargs = { 'host' => $host, 'port' => $port };
 | |
|   my $conn = new Net::HandlerSocket($hsargs);
 | |
|   if (defined($conn) && defined($conf{hspass})) {
 | |
|     $conn->auth($conf{hspass});
 | |
|   }
 | |
|   return $conn;
 | |
| }
 | |
| 
 | |
| 
 | |
| init_conf();
 | |
| 
 | |
| 1;
 | |
| 
 |