Home > OS >  GBase 8 a MPP Cluster ODBC application example
GBase 8 a MPP Cluster ODBC application example

Time:12-30

one Python calls GBase 8 a MPP Cluster ODBC driver
Using the python language called GBase 8 a MPP Cluster ODBC, need to download and install
Python and pyodbc package, in the case of python2.7
1. From http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz
2. Downloaded from http://pyodbc.googlecode.com/files/pyodbc-3.0.6.zip
Pyodbc - 3.0.6 installation package,
3. Python2.7 installation, first to extract the Python - 2.7.3. TGZ, then execute the following command:
./configure -- prefix=/opt/python2.7
Make
Make install
4. Pyodbc - 3.0.6 installation, first to extract the pyodbc - 3.0.6. Zip, then execute the following command:
/opt/python2.7/bin/python setup. Py build install
Such python2.7 and pyodbc - 3.0.6 installation is successful, can undertake python console into
Line, as shown in the following:
[root @ GBase pyodbc - 3.0.6] #/opt/python2.7/bin/python
Python 2.7.3 (default, Jul 16, 2012, 18:45:35)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2
Type "help", "copyright", "credits" or "license" for more
Information.
> The import pyodbc
>
No error when using the import pyodbc reference pyodbc python install successful,
The next is to create the ODBC data source, to create the ODBC data source methods refer to 3.2.2, if the
And to the Chinese, so be sure to set the GBase 8 a MPP Cluster ODBC driver character set (the word
Operator set conform to cluster installation when the default character set), this use case GBase 8 a MPP
Cluster ODBC character set as UTF8,
After the success of the create the ODBC data source you can use the following python scripts test:
#!/opt/python2.7/bin/python
# coding: utf8
The import pyodbc
Conn_str='DSN=gbase; '
Conn=pyodbc. Connect (conn_str)
Cursor=conn. Cursor ()
Cursor. The execute (" drop table if the exists t_pyodbc ")
Cursor. The execute (" create table t_pyodbc (a varchar (100), int) b ")
Cursor. Execute (" insert into t_pyodbc (a, b) values (?,?,?,?,? ,?) ", 'pyodbc,
"10)
Cursor. Execute (" insert into t_pyodbc (a, b) values (?,?,?,?,? ,?) "And" ntu
Gm ', 11)
MIT ()
cursor.comCursor. The execute (" select * from t_pyodbc ")
The row=cursor. Fetchall ()
For r in a row:
Print "% s % d % (r [0]. Encode (' utf8), r [1])

two The perl language called GBase 8 a MPP Cluster ODBC driver
Using the python language called GBase 8 a MPP Cluster ODBC, need to download and install perl
And DBD: : ODBC package, perl 5.14, for example:
1. From http://downloads.activestate.com/ActivePerl/releases/5.14.2.1402/Act
IvePerl -
5.14.2.1402 - x86_64 - Linux - glibc - 2.3.5-295342. The tar. Gz download perl 5.14
The installation package,
2. From http://mirrors.sohu.com/CPAN/authors/id/M/MJ/MJEVANS/DBD-ODBC-1.39.t
Ar. Download DBD - ODBC 1.39 gz,
3. Install perl 5.14, perl default installed at/opt/ActivePerl - 5.14 directory,
4. Install DBD - ODBC - 1.39, to extract the DBD - ODBC - 1.39. Tar. Gz, then perform the following
Command to install:
/opt/ActivePerl - 5.14/bin/perl Makefile. PL
Make
Make install
5. The next is to create the ODBC data source, to create the ODBC data source methods refer to 3.2.2, such as
Fruit comes to Chinese, so be sure to set the GBase 8 a MPP Cluster ODBC driver character set (the
Character set needs to be consistent with the cluster installation when the default character set), this use case GBase 8 a MPP
Cluster ODBC character set as UTF8,
#!/opt/ActivePerl - 5.14/bin/perl
Use class: : DBI.
Use encoding 'utf-8';
$DBH=class: : DBI - & gt; The connect (' class: : dbi: ODBC: gbase8a ', 'gbase', 'gbase20110531');
My $STH=$DBH - & gt; Prepare (" drop table if the exists t_plodbc ");
$STH - & gt; The execute ();
My $STH=$DBH - & gt; Prepare (" create table t_plodbc (a varchar (100), b
Int) ");
$STH - & gt; The execute ();
My $STH=$DBH - & gt; Prepare (" insert into t_plodbc values (' ntu general,
10) ");
$STH - & gt; The execute ();
My $STH=$DBH - & gt; Prepare (" select * from t_plodbc ");
$STH - & gt; The execute ();
While (@ data=https://bbs.csdn.net/topics/$sth-> fetchrow_array ())
{
Print "$data [0] \ n";
}

3. The PHP language called GBase 8 a MPP Cluster ODBC driver
<?
$conn_str="DRIVER=GBase 8 a MPP Cluster ODBC 8.3
Driver; SERVER=192.168.9.173; UID=gbase; The PWD=gbase20110531; The database
=test; Charset=GBK; LOG_QUERY=1 ";
$sql_drop="drop table if the exists t_php";
$sql_create="create table t_php (col1 int, col2 varchar (100))";
$sql_insert1="insert into t_php values (1," ABC ");
$sql_insert2="insert into t_php values (2, 'ntu general)";
$sql_select="select * from t_php";
$conn=odbc_connect ($conn_str, ""," ");
if(! ($conn)) {
Echo "get connection:" odbc_errormsg ($conn);
Echo "& lt; Br> ";
}
Odbc_exec ($conn, $sql_drop);
If (odbc_error ()) {
Echo "drop table:" odbc_errormsg ($conn);
Echo "& lt; Br> ";
}
Odbc_exec ($conn, $sql_create);
If (odbc_error ()) {
Echo "create table:" odbc_errormsg ($conn);
Echo "& lt; Br> ";
}
/* */insert data
Odbc_exec ($conn, $sql_insert1);
If (odbc_error ()) {
Echo "insert". Odbc_errormsg ($conn);
Echo "& lt; Br> ";
}
Odbc_exec ($conn, $sql_insert2);
If (odbc_error ()) {
Echo "insert". Odbc_errormsg ($conn);
Echo "& lt; Br> ";
}
The select data *//*
$rs=odbc_exec ($conn, $sql_select);
If (odbc_error ()) {
Echo "select". Odbc_errormsg ($conn);
Echo "& lt; Br> ";
}
While (odbc_fetch_row ($rs)) {
Echo "\ n" odbc_result ($rs, "col1"). "\ t". Odbc_result ($rs,
"Col2"). "\ n";
Echo "& lt; Br> ";
}
Odbc_exec ($conn, $sql_drop);
If (odbc_error ()) {
Echo odbc_errormsg ($conn);
}
The odbc_close ($conn);
?>

CodePudding user response:

????? nullnull
  • Related