Sorry, I'm probably confusing you by getting off topic.

I think memLZF just stores it compressed in memory. To compress it for transfer over the wire you want to alter this line to say

conn.createStatement().execute(
                "script to 'memFS:script.sql COMPRESSION GZIP'");

To read it back you need to do the opposite process, I assume you write to the file in-memory with something like

os = FilePath.get("memFS:script.sql").newOutputStream();

then write to the output stream to populate the in-memory file.

then

conn.createStatement().execute("runscript memFS:script.sql COMPRESSION GZIP");

I'm not sure how to clear the in-memory file to get that memory back or how long it lasts in memory?

You might be safer just using SCRIPT TO, read the script from the result set, then transfer, then execute the script manually without using RUNSCRIPT... This in-memory file stuff might just be complicating it, but I think it's pretty nifty! :)




On 2/01/2014 10:40 PM, Rob Oaks wrote:

Just to be clear (and keeping in mind that I'm new to H2!), to run the in-memory script would I use:

conn.createStatement().execute("runscript FilePath.get('memFS:script.sql')");

Can I also substitute memLZF for memFS so that the compressed version of the string is being sent over the wire?



On Thursday, January 2, 2014 6:39:21 AM UTC-5, 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 <rh...@exemail.com.au
    <javascript:>> 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
        <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...@googlegroups.com
        <javascript:>.
        To post to this group, send email to h2-da...@googlegroups.com
        <javascript:>.
        Visit this group at http://groups.google.com/group/h2-database
        <http://groups.google.com/group/h2-database>.
        For more options, visit
        https://groups.google.com/groups/opt_out
        <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.

Reply via email to