External Filesystem Access

Sybase has an extremely rich mechanism for interaction with the native filesystem, exposed via Component Integration Services' Proxy Table support. To enable it, an administrator must execute

sp_configure "enable cis", 1
sp_configure "enable file access", 1

The server need not be rebooted; as soon as the configuration is changed the external filesystem mechanism should be available. To read the contents of an external file, you create a proxy table for it, and then “select” from it as you would a normal table:

create proxy_table foo_txt external file at "c:\temp\foo.txt"
select * from foo_txt

The table is created by default with a single VARCHAR column of width 255 characters. If you need to handle more characters per line, you can use the “create existing table” syntax:

create existing table foo_txt (record varchar(1000) null)
external file at "c:\temp\foo.txt"

You can natively insert, select, and truncate the table, but you cannot update it, though you can edit foo.txt using the update statement and a temporary table. Suppose foo.txt contains the following:

record
------
hello world
line 2
line three

and you wish to edit the first line to read “goodbye world,” you can do so like this:

create table #foo( record varchar(1000))
insert into #foo select * from foo_txt
update #foo set record='goodbye world' where record like 'hello world'
select * from #foo
truncate table foo_txt
insert into foo_txt select * from #foo
drop table #foo

Note that there ...

Get The Database Hacker's Handbook: Defending Database Servers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.