Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1856339
  • 博文数量: 473
  • 博客积分: 13997
  • 博客等级: 上将
  • 技术积分: 5953
  • 用 户 组: 普通用户
  • 注册时间: 2010-01-22 11:52
文章分类

全部博文(473)

文章存档

2014年(8)

2013年(38)

2012年(95)

2011年(181)

2010年(151)

分类: 数据库开发技术

2010-02-10 13:33:00

# some materials about unixodbc
#http://www.easysoft.com/developer/interfaces/odbc/linux.html#unixodbc most worthy to read

#Chen peng MSN:peng.ch@hotmail.com 2006-4-28

# The unixODBC source distribution is a gzipped tar file on
# Uncompress it in the dir /usr/local and then untar the resultant file.

gunzip unixODBC-2.2.12.tar.gz
tar -xzvf unixODBC-2.2.12.tar
./configure --prefix=/usr/local/unixODBC-2.2.12 --includedir=/usr/include --libdir=/usr/lib -bindir=/usr/bin --sysconfdir=/etc

# create an ODBC driver template file and run odbcinst. filename : template_file

/*
In this case your template file must contain the Driver and Description attributes at a minimum and optionally the Setup attribute e.g.
 
 [DRIVER_NAME]
 Description = description of the ODBC driver
 Driver = path_to_odbc_driver_shared_object
 Setup = path_to_driver_setup_shared_object

e.g:
 SkyKonnect:/ # cat /usr/local/etc/odbcinst.ini
 [MySQL]
 Description     = ODBC for MySQL
 Driver          = /usr/lib/libmyodbc3.so
 Setup           = /usr/local/lib/libodbcmyS.so
 FileUsage       = 2
 UsageCount      = 2

*/

odbcinst -f template_file -d -i

# You can list all installed ODBC drivers with:
odbcinst  -s -q
/*
 SkyKonnect:/usr/local/unixODBC-2.2.11/ODBCConfig # odbcinst  -s -q
 [myodbc3]
*/

# you can locate the odbcinst.ini file used to defined drivers as below If unixODBC is already installed :
odbcinst -j
/*
 SkyKonnect:/usr/local/unixODBC-2.2.11/ODBCConfig # odbcinst  -j
 unixODBC 2.2.11
 DRIVERS............: /usr/local/etc/odbcinst.ini
 SYSTEM DATA SOURCES: /usr/local/etc/odbc.ini
 USER DATA SOURCES..: /root/.odbc.ini
*/

/** Edit the SYSTEM or USER DSN ini file ( odbc.ini or .odbc.ini) and add a data source using the syntax:
   
    [ODBC_datasource_name}
    Driver = driver_name
    Description = description_of_data_source
    attribute1 = value
    .
    .
    attributen = value*

*/

/*
 SkyKonnect:/ # cat /root/.odbc.ini
 [myodbc3]
 Driver          = /usr/lib/libmyodbc3.so
 Description     = MyODBC 3.51 Driver DSN
 SERVER          = 192.168.1.9
 PORT            = 3306
 USER            = root
 Password        = root
 Database        = wapmax
 OPTION          = 3
 SOCKET          =
*/

# You can list user and system data sources with:
odbcinst  -q -s
/*
 SkyKonnect:/usr/local/unixODBC-2.2.11/ODBCConfig # odbcinst  -q -s
 [myodbc3]
*/

# The format of isql's command line for testing connection is:
isql -v DSN_NAME db_username db_password
/*
 SkyKonnect:/ # isql myodbc3 root root
 +---------------------------------------+
 | Connected!                            |
 |                                       |
 | sql-statement                         |
 | help [tablename]                      |
 | quit                                  |
 |                                       |
 +---------------------------------------+
 SQL>
*/

#Tracing ODBC calls
/*
The unixODBC driver manager can write a trace of call ODBC calls made to a file.
This can be a very useful debugging aid but it should be remembered that tracing will slow your application down.

Locate your odbcinst.ini file  and add a section to this file like:

 [ODBC]
 TraceFile = /tmp/sql.log
 Trace = Yes

You can use any file for the TraceFile argument and it does not need to pre-exist.
The permissions on the odbcinst.ini may be such that you need to be the root user.
*/

阅读(978) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~