doc/fuse_db.sql
changeset 31 7804cd7b5cd5
parent 27 461be4cd34a3
child 32 90e14e0df133
--- a/doc/fuse_db.sql	Thu Oct 16 22:56:29 2008 +0300
+++ b/doc/fuse_db.sql	Fri Oct 17 02:04:03 2008 +0300
@@ -1,11 +1,27 @@
-CREATE TABLE inodes (ino serial4 primary key, type char(3), mode int2, size int8);
-CREATE TABLE file_tree ("offset" serial4 primary key, name varchar(256) NOT NULL, parent int4 references inodes(ino) NOT NULL, inode int4 references inodes(ino) NOT NULL);
+CREATE TABLE inodes (
+    ino serial4 primary key, 
+    type char(3) NOT NULL, 
+    mode int2 NOT NULL, 
+    data oid
+);
 
-INSERT INTO inodes VALUES (1, 'DIR', 365, 0);
-INSERT INTO inodes VALUES (2, 'REG', 292, 0);
-INSERT INTO file_tree (name, parent, inode) VALUES ('foo', 1, 2);
+CREATE TABLE file_tree (
+    "offset" serial4 primary key, 
+    name varchar(256), 
+    parent int4 references inodes(ino), 
+    inode int4 references inodes(ino) NOT NULL
+);
 
-ALTER TABLE file_tree ALTER COLUMN name DROP NOT NULL;
-ALTER TABLE file_tree ALTER COLUMN parent DROP NOT NULL;
-INSERT INTO file_tree (name, parent, inode) VALUES (NULL, NULL, 1);
+INSERT INTO inodes VALUES 
+    (1, 'DIR', 365, NULL),
+    (2, 'REG', 292, lo_create(0));
 
+INSERT INTO file_tree (name, parent, inode) VALUES 
+    (NULL,  NULL,   1   ),
+    ('foo', 1,      2   );
+
+CREATE FUNCTION lo_size (oid) RETURNS int4 LANGUAGE SQL STABLE RETURNS NULL ON NULL INPUT AS 'select lo_lseek(lo_open($1, 262144), 0, 2);';
+CREATE FUNCTION lo_pread (IN fd int4, IN len int4, IN "off" int4) RETURNS bytea LANGUAGE SQL STRICT AS 'select lo_lseek($1, $3, 0); select loread($1, $2);';
+CREATE FUNCTION lo_pwrite (IN fd int4, IN buf bytea, IN "off" int4) RETURNS int4 LANGUAGE SQL STRICT AS 'select lo_lseek($1, $3, 0); select lowrite($1, $2);';
+CREATE FUNCTION lo_otruncate (IN oid, IN len int4) RETURNS oid LANGUAGE SQL STRICT AS 'select lo_truncate(lo_open($1, 393216), $2); select $1;';
+