Wow, I didn't realise you could use it out of the context of a H2
connection URL. That is pretty awesome :)
Thanks, Ryan
On 2/01/2014 7:39 PM, Thomas Mueller wrote:
Hi,
> SCRIPT TO mem:myobject COMPRESSION GZIP
You can do that already, using the H2 file system abstraction:
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import org.h2.store.fs.FilePath;
import org.h2.util.IOUtils;
public class TestSimpleDb {
public static void main(String[] args) throws Exception {
Connection conn = DriverManager.getConnection(
"jdbc:h2:mem:test");
conn.createStatement().execute(
"create table test(id int) as select 1");
conn.createStatement().execute(
"script to 'memFS:script.sql'");
InputStream in = FilePath.get(
"memFS:script.sql").newInputStream();
byte[] script = IOUtils.readBytesAndClose(in, -1);
System.out.println(new String(script, "UTF-8"));
}
}
Or you can just run "script" and process the result set.
Regards,
Thomas
On Thu, Jan 2, 2014 at 12:14 PM, Ryan How <r...@exemail.com.au
<mailto:r...@exemail.com.au>> wrote:
On 2/01/2014 6:40 PM, Thomas Mueller wrote:
> Would be nice if there was some java in-memory file abstraction
I don't understand, you can already use the file system
abstraction of H2. You can also use databases that persist to an
in-memory file system, using the database URL jdbc:h2:memFS:test
or jdbc:h2:memLZF:test. See also
http://h2database.com/html/advanced.html#file_system
I meant that because RUNSCRIPT reads from a file or a URL, it
would be good to be able to pass it file object that just points
to an in memory string. Nothing H2 specific, just a way to use the
java file API for accessing custom data structures.
So he could do something like SCRIPT TO mem:myobject COMPRESSION
GZIP, which would put the compressed data into some byte[] and
then transfer it, and then RUNSCRIPT mem:myobject COMPRESSION GZIP
which reads from the byte array. Would save all the custom
compressing / uncompressing and manually executing the SQL
statements. Not that it would be hard...
--
You received this message because you are subscribed to the Google
Groups "H2 Database" group.
To unsubscribe from this group and stop receiving emails from it,
send an email to h2-database+unsubscr...@googlegroups.com
<mailto:h2-database%2bunsubscr...@googlegroups.com>.
To post to this group, send email to h2-database@googlegroups.com
<mailto:h2-database@googlegroups.com>.
Visit this group at http://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google
Groups "H2 Database" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to h2-database+unsubscr...@googlegroups.com.
To post to this group, send email to h2-database@googlegroups.com.
Visit this group at http://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups "H2
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to h2-database+unsubscr...@googlegroups.com.
To post to this group, send email to h2-database@googlegroups.com.
Visit this group at http://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/groups/opt_out.