Java port of the sqlite3 shell courtesy of the brilliant NestedVM UNIX/MIPS emulation environment:
http://www.sqlite.org/contrib?orderby=date java -jar sqlite3sh.jar SQLite version 3.3.8 Enter ".help" for instructions sqlite> create table abc(a, b, c); sqlite> insert into abc values (4, 5, 'frog'); sqlite> insert into abc values (13.4, 'A', null); sqlite> select * from abc; 4|5|frog 13.4|A| sqlite> update abc set c = 'something'; sqlite> .dump BEGIN TRANSACTION; CREATE TABLE abc(a, b, c); INSERT INTO "abc" VALUES(4, 5, 'something'); INSERT INTO "abc" VALUES(13.4, 'A', 'something'); COMMIT; sqlite> .q Warning: No database file locking is performed by sqlite3sh.jar - use on a copy of a database file or risk data corruption. (If someone provides a fcntl() patch for NestedVM, please post it to this list.) Note: this is not a JDBC driver. In theory you could use NestedVM to port Christian Werner's SQLite JDBC driver, but it would require a fair bit of work.
diff -rN -u old-nestedvm/src/org/ibex/nestedvm/Interpreter.java new-nestedvm/src/org/ibex/nestedvm/Interpreter.java --- old-nestedvm/src/org/ibex/nestedvm/Interpreter.java 2006-10-08 23:16:14.000000000 -0400 +++ new-nestedvm/src/org/ibex/nestedvm/Interpreter.java 2006-10-09 11:44:53.000000000 -0400 @@ -781,7 +781,7 @@ Interpreter emu = new Interpreter(image); java.lang.Runtime.getRuntime().addShutdownHook(new Thread(emu.new DebugShutdownHook())); int status = emu.run(argv); - System.err.println("Exit status: " + status); + //System.err.println("Exit status: " + status); System.exit(status); } } diff -rN -u old-nestedvm/src/org/ibex/nestedvm/Runtime.java new-nestedvm/src/org/ibex/nestedvm/Runtime.java --- old-nestedvm/src/org/ibex/nestedvm/Runtime.java 2006-10-08 23:16:15.000000000 -0400 +++ new-nestedvm/src/org/ibex/nestedvm/Runtime.java 2006-10-09 13:57:36.000000000 -0400 @@ -809,6 +809,14 @@ copyout(buf,addr,n); return n; } + + /** The ftruncate syscall */ + private int sys_ftruncate(int fdn, long length) throws ErrnoException { + if (fdn < 0 || fdn >= OPEN_MAX) return -EBADFD; + if (fds[fdn] == null) return -EBADFD; + fds[fdn].ftruncate(length); + return 0; + } /** The close syscall */ private int sys_close(int fdn) { @@ -1017,6 +1025,10 @@ return 0; case F_GETFD: return closeOnExec[fdn] ? 1 : 0; + case F_GETLK: + case F_SETLK: + //if(STDERR_DIAG) System.err.println("WARNING: fcntl option not supported: " + cmd); + return 0; default: if(STDERR_DIAG) System.err.println("WARNING: Unknown fcntl command: " + cmd); return -ENOSYS; @@ -1058,6 +1070,7 @@ case SYS_close: return sys_close(a); case SYS_read: return sys_read(a,b,c); case SYS_lseek: return sys_lseek(a,b,c); + case SYS_ftruncate: return sys_ftruncate(a,b); case SYS_getpid: return sys_getpid(); case SYS_calljava: return sys_calljava(a,b,c,d); case SYS_gettimeofday: return sys_gettimeofday(a,b); @@ -1143,6 +1156,9 @@ /** Write. Should return the number of bytes written or throw an IOException on error */ public int write(byte[] a, int off, int length) throws ErrnoException { throw new ErrnoException(EBADFD); } + /** ftruncate */ + public void ftruncate(long length) throws ErrnoException { throw new ErrnoException(EBADFD); } + /** Seek in the filedescriptor. Whence is SEEK_SET, SEEK_CUR, or SEEK_END. Should return -1 on error or the new position. */ public int seek(int n, int whence) throws ErrnoException { return -1; } @@ -1215,6 +1231,14 @@ throw new ErrnoException(EIO); } } + + public void ftruncate(long length) throws ErrnoException { + try { + data.ftruncate(length); + } catch(IOException e) { + throw new ErrnoException(EIO); + } + } protected void _close() { try { data.close(); } catch(IOException e) { /*ignore*/ } } } diff -rN -u old-nestedvm/src/org/ibex/nestedvm/util/Seekable.java new-nestedvm/src/org/ibex/nestedvm/util/Seekable.java --- old-nestedvm/src/org/ibex/nestedvm/util/Seekable.java 2006-10-08 23:16:14.000000000 -0400 +++ new-nestedvm/src/org/ibex/nestedvm/util/Seekable.java 2006-10-09 11:49:21.000000000 -0400 @@ -14,6 +14,10 @@ public abstract void close() throws IOException; public abstract int pos() throws IOException; + public void ftruncate(long length) throws IOException { + throw new IOException("ftruncate not implemented for " + getClass()); + } + public int read() throws IOException { byte[] buf = new byte[1]; int n = read(buf,0,1); @@ -83,6 +87,7 @@ public int pos() throws IOException { return (int) raf.getFilePointer(); } public int length() throws IOException { return (int)raf.length(); } public void close() throws IOException { raf.close(); } + public void ftruncate(long length) throws IOException { raf.setLength(length); } } public static class InputStream extends Seekable {
----------------------------------------------------------------------------- To unsubscribe, send email to [EMAIL PROTECTED] -----------------------------------------------------------------------------