暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Java版本的Sybase ASE ISQL命令行

数据库杂记 2023-02-28
134

1. 背景



曾经,经常遇到有人问,Sybase (ASE, 国内基本上把以前的Sybase ASE数据库简称为Sybase数据库,  现在官方已经叫做SAP ASE,在我看来无所谓。只要大家知道它是哪个数据库就行了。) 数据库有没有短小点的命令行工具。我说,昨个短小法?


Sybase ASE确实自带一个isql命令行,功能也很强大。但是也有其局限性。在Cloud环境下,就更是如此,比如我想在Jenkins Job上连接ASE的一个实例,并且那个实例只能本地执行。什么意思呢?就是说,你不能在远程直接通过ASE的isql命令行连接cloud上的数据库,必须通过特定的tunnel。


Tunnel相比较于直连,就差那么点意思了。
1.  它一般需要的是Java的jdbc连接。这个你就需要为其提供专门的客户端。

2.  Tunnel可能在某些版本不是很稳定,你就多了一份担心。

如果稳定的话,大可以使用DBEaver,  DBVisualizer等第三方工具去连接了,然后做一些日常操作是可以的。但是做Jenkins Job是不行的。


于是,既能提供日常操作,同时又能调用SQL脚本用于远程执行的Java isql客户端,就有存在的必要了。



2. ase.isql 开源项目


基于上述需求,我开源了一个短小的ase.isql命令行工具,完全java实现,基于现有的Sybase Jconn JDBC驱动。

它的最大好处是可以执行一个SQL文件,并且返回最后的处理结果,用于Jenkins Job当中进行一些批处理维护,非常方便。


Project 地址:https://github.com/iihero/ase.isql


使用起来非常简单:


java -jar ase.isql-1.0.2-spring-boot.jar -S jdbc:sybase:Tds:localhost:30015/MYDB -E -U <username> -P <password> [-I sql_input_file]


不带输入文件:

java -jar ase.isql-1.0.2-spring-boot.jar -S jdbc:sybase:Tds:localhost:30015/MYDB -E -U <username> -P <password>

Enter a query: 1 > select 1

------------------ Result set 1 -----------------------

Columns: [ 11 1 rows Affected.

Enter a query: 1 > quit


直接pipe命令行:

echo sp_helpdb tempdb  | java -jar ase.isql-1.0.2-spring-boot.jar  -S "jdbc:sybase:Tds:localhost:30015/MYDB?ENABLE_SSL=true&SSL_TRUST_ALL_CERTS=true"  -U * -P *

结果:
Enter a query:
1 >
------------------ Result set 1 -----------------------

Columns:        name    db_size owner   dbid    created durability      lobcomplvl      inrowlen        status
1]    tempdb       124.0 MB   sa         2    Mar 222022    no_recovery              0          NULL        select into/bulkcopy/pllsort, trunc log on chkpt, abort tran on log full, mixed log and data, allow wide dol rows
1 rows Selected.

------------------ Result set 2 -----------------------

Columns:        name    attribute_class attribute       int_value       char_value      comments
1]    tempdb  buffer manager  cache binding           1       tempdb_cache    null
1 rows Selected.


------------------ Result set 3 -----------------------

Columns:        device_fragments        size    usage   created free_kbytes
1]    master        24.0 MB    -- unused by any segments --   Mar  6 2019  2:10AM                24480
2]    tempdbdev            100.0 MB   data and log    Mar  6 2019  2:11AM               100736
2 rows Selected.


带输入文件:

exec sp_savespace_lob 16384

java -jar ase.isql-1.0.2-spring-boot.jar -S jdbc:sybase:Tds:localhost:30015/MYDB -E -U \<username\> -P <password\> -I abc.sql

output:


Warning: Row size (17743 bytes) could exceed row size limit, which is 16300 bytes.
...... 
sp_chgattribute ABCD, "dealloc_first_txtpg"1
'dealloc_first_txtpg' attribute of object 'SMP_CLOUDBUILD_SIGNING_PROFILE' changed to 1.
alter table ABCD modify xxxx  in row (16384)
Warning: ALTER TABLE operation MODIFY IN ROW did not affect column 'xxxx '.

Warning: Row size (32767 bytes) could exceed row size limit, which is 16300 bytes.

SQLSTATUS = 0
sp_chgattribute ABCD, "dealloc_first_txtpg"1
'dealloc_first_txtpg' attribute of object 'ABCD ' changed to 1.
alter table ABCD modify xxx in row (16384)
Warning: ALTER TABLE operation MODIFY IN ROW did not affect column 'xxx '.

Warning: Row size (32767 bytes) could exceed row size limit, which is 16300 bytes.

SQLSTATUS = 0
Unexpected exception : SqlState: 010P4 java.sql.SQLWarning: 010P4: An output parameter was received and ignored., ErrorCode: 0
2028 rows Affected.


调用起来也非常方便。



文章转载自数据库杂记,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论