Hi All, I am testing the position function against blob column. The blob values are represented as pair of hex for each byte.
my expectation is the position function should return the index value relative to the pairing. sql> select position (x'aa' , x'aabbcc') from dual; result : 1 expected result: 1 (ok) sql> select position (x'bb' , x'aabbcc') from dual; result : 3 expected result: 2 sql>select position (x'cc' , x'aabbcc') from dual; result : 5 expected result: 3 -- 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/h2-database. For more options, visit https://groups.google.com/d/optout.
/* * Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0, * and the EPL 1.0 (http://h2database.com/html/license.html). * Initial Developer: H2 Group */ package org.h2.samples; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.Statement; import org.h2.tools.DeleteDbFiles; /** * A very simple class that shows how to load the driver, create a database, * create a table, and insert some data. */ public class TestPositionBlob { /** * Called when ran from command line. * * @param args ignored */ public static void main(String... args) throws Exception { // delete the database named 'test' in the user home directory DeleteDbFiles.execute("~", "test", true); Class.forName("org.h2.Driver"); Connection conn = DriverManager.getConnection("jdbc:h2:~/test"); Statement stat = conn.createStatement(); // this line would initialize the database // from the SQL script file 'init.sql' // stat.execute("runscript from 'init.sql'"); stat.execute("create table testBlob (colblobpos blob, colblob blob)"); stat.execute("insert into testBlob values ( x'aa', x'aabbccdd')"); stat.execute("insert into testBlob values ( x'bb', x'aabbccdd')"); stat.execute("insert into testBlob values ( x'cc', x'aabbccdd')"); stat.execute("insert into testBlob values ( x'dd', x'aabbccdd')"); ResultSet rs = stat.executeQuery("select colblobpos, colblob, position(colblobpos, colblob) from testBLob"); while(rs.next()) System.out.println(rs.getString(1) + "|" + rs.getString(2) + "|" + rs.getLong(3)); stat.close(); conn.close(); } }
