Archive for the ‘linux and unix’ Category
星期五, 十一月 6th, 2009
oracle调用c函数(续)
本来挺简单的问题,可惜我们系统安装的有问题。
oracle是64位的,而gcc是32位的。
这样在调用的过程会报错误。
ERROR at line 1:
ORA-06520: PL/SQL: Error loading external library
ORA-06522: ld.so.1: extproc: fatal:
/opt/oracle/products/10.2.0/lib/sunwg.so: wrong ELF class: ELFCLASS32
ORA-06512: at "ETL.H_EXECUTE_CMD", line 1
重装64位的gcc也是个麻烦事。
从网上查了半天终于发现个好办法。
修改LD_LIBRARY_PATH=/opt/oracle/products/10.2.0/lib为
LD_LIBRARY_PATH=/opt/oracle/products/10.2.0/lib32
这样调用32位的oracle lib库。
重新启动listener。
搞定。
><
Posted in linux and unix, oracle, shell,perl,python,lex,yacc,c | No Comments »
星期三, 十一月 4th, 2009
C通过freetds接口访问SQL SERVER数据库
代码举例如下:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include </usr/local/freetds/include/sybfront.h>
#include </usr/local/freetds/include/sybdb.h>
int main(void)
{
char szUsername[32] = "robit";
char szPassword[32] = "littlerobit";
char szDBName[32] = "shxn";
char szServer[32] = "10.16.14.67:1433";
//初始化db-library
dbinit();
//连接数据库
LOGINREC *loginrec = dblogin();
DBSETLUSER(loginrec, szUsername);
DBSETLPWD(loginrec, szPassword);
DBPROCESS *dbprocess = dbopen(loginrec, szServer);
if(dbprocess == FAIL)
{
printf("ASB>>Conect MS SQL SERVER fail\n");
...
Posted in linux and unix, shell,perl,python,lex,yacc,c | No Comments »
星期三, 十一月 4th, 2009
freetds中使用freebcp导数据
freebcp是freetds中提供的功能和bcp类似的数据导出导入工具
[oracle@dw_testdb sql_server]$ freebcp
usage: freebcp [[database_name.]owner.]table_name {in | out} datafile
[-m maxerrors] [-f formatfile] [-e errfile]
[-F firstrow] [-L lastrow] [-b batchsize]
[-n] [-c] [-t field_terminator] [-r row_terminator]
[-U username] [-P password] [-I interfaces_file] [-S server]
[-v] [-d] [-h "hint [,...]" [-O "set connection_option on|off, ...]"
[-A packet size] [-T text ...
Posted in linux and unix | No Comments »
星期三, 十一月 4th, 2009
在LINUX上访问Microsoft SQL Server数据库
Microsoft SQL Server在linux环境下没有客户端,所以不能直接在linux通过客户端访问SQL SERVER数据库。
FreeTDS提供一套函数库, 让Unix与Linux环境的程式可以通过它访问Microsoft SQL Server与Sybase database。
一,FreeTDS安装
Step 1:下载FreeTDS
去FreeTDS官方网址http://www.freetds.org/下载freetds-stable.tar软件包。
Step 2:解压并安装
$ tar zxvf freetds-stable.tgz(解压)
$ ./configure --prefix=/usr/local/freetds --with-tdsver=8.0 --enable-msdblib
$ make
$ make install(需要root执行)
Step 3:配置
修改 /etc/ld.so.conf, 加入 /usr/local/freetds/lib; 完成後再執行 ldconfig
修改用户profile
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/freetds/lib/
export FREETDS=/usr/local/freetds
export PATH=$PATH:$FREETDS/bin
二,FreeTDS的测试
1,直接连接
tsql -H 10.16.14.67 -p 1433 -U robit -P littlerobit
参数说明:
-H:hostname
-P:port
-U:username
-P:password
[oracle@dw_testdb ~]$ tsql -H 10.16.14.67 -p 1433 -U robit -P littlerobit
locale is ...
Posted in linux and unix | No Comments »
星期五, 十月 30th, 2009
FIFO有时被称为命名管道。管道只能由相关进程使用,它们共同的祖先进程创建了管道。
但是,通过FIFO,不相关的进程也能交换数据。
举例如下:
步骤1:创建FIFO
[oracle@dw_testdb oci]$mkfifo 7.dat
[oracle@dw_testdb oci]$ ll 7.dat
prw-r--r-- 1 oracle dba 0 Oct 30 11:48 7.dat
p为FIFO的标识
步骤2:创建SQLLDR的控制文件8.ctl
load data
infile '/home/oracle/sunwg/oci/7.dat'
insert into table sunwg.sunwg
(id)
步骤3:进程1向管道写入数据
[oracle@dw_testdb oci]$cat 6.txt > 7.dat
进程挂起等待读进程从FIFO中读数据
步骤四:进程2从管道读并SQLLDR到oracle数据库中
[oracle@dw_testdb oci]$ sqlldr userid=sunwg/test@dwtest control="8.ctl"
SQL*Loader: Release 11.1.0.7.0 - Production on Fri Oct 30 11:48:32 2009
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Commit point reached - ...
Posted in linux and unix | No Comments »