Java Code Examples for com.almworks.sqlite4java.SQLiteStatement#columnString()

The following examples show how to use com.almworks.sqlite4java.SQLiteStatement#columnString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SQLite3StatementBindInvoker.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
@Nullable
public static Object bind(SQLiteStatement stmt, Class<?> type, int index) {
   try {
      if (type.equals(String.class)) {
         return stmt.columnString(index);
      } else if (type.equals(Integer.class) || type.equals(int.class) ) {
         return stmt.columnInt(index);
      } else if (type.equals(Long.class) || type.equals(long.class)) {
         return stmt.columnLong(index);
      } else if (type.equals(Byte.class) || type.equals(byte.class) ) {
         return (byte)stmt.columnInt(index);
      } else if ( type.equals(Boolean.class) || type.equals(boolean.class) ) {
         return stmt.columnInt(index) != 0;
      } else if (type.equals(Double.class) || type.equals(double.class)) {
         return stmt.columnDouble(index);
      } else if (type.equals(float.class) || type.equals(Float.class)) {
         return (float)stmt.columnDouble(index);
      } else if (type.equals(Serializable.class)) {
         return stmt.columnBlob(index);
      }
   } catch (SQLiteException e) {
      log.error("sql bind invoker could not invoke:" , e);
   }

   return null;
}
 
Example 2
Source File: DbUtils.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public static <T> T extract(SQLiteStatement stmt, Class<T> type, int idx) throws Exception {
   if (type == String.class) {
      return (T) stmt.columnString(idx);
   } else if (type == int.class || type == Integer.class) {
      return (T) (Integer) stmt.columnInt(idx);
   } else if (type == long.class || type == Long.class) {
      return (T) (Long) stmt.columnLong(idx);
   } else if (type == double.class || type == Double.class) {
      return (T) (Double) stmt.columnDouble(idx);
   } else if (type == byte[].class) {
      return (T) stmt.columnBlob(idx);
   } else if (type == Object.class) {
      return (T) stmt.columnValue(idx);
   } else {
      throw new DbException("cannot get column type: " + type);
   }
}
 
Example 3
Source File: ReflexDao.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Override
public AddressKeyValue extract(SQLiteConnection conn, SQLiteStatement stmt) throws Exception {
   String addr = stmt.columnString(0);
   String key = stmt.columnString(1);
   String val = stmt.columnString(2);
   return new AddressKeyValue(addr,key,val);
}
 
Example 4
Source File: SQLite3Table.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Override
public SQLite3TableInfo extract(SQLiteConnection conn, SQLiteStatement stmt) throws Exception {
   int cid = stmt.columnInt(0);
   String name = stmt.columnString(1);
   String type = stmt.columnString(2);
   String notnull = stmt.columnString(3);
   String defaultValue = stmt.columnString(4);
   int pk = stmt.columnInt(5);
   return new SQLite3TableInfo(cid,name,type,notnull,defaultValue,pk);
}
 
Example 5
Source File: ConfigService.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Override
public KeyValuePair extract(SQLiteConnection conn, SQLiteStatement stmt) throws Exception {
   String key = stmt.columnString(0);
   String val = stmt.columnString(1);
   Long lastUpdateTime = stmt.columnLong(2);
   Long lastReportTime = stmt.columnLong(3);

   ValueWithTime<String> vwt = new ValueWithTime(val, lastUpdateTime, lastReportTime);
   return new KeyValuePair(key,vwt);
}
 
Example 6
Source File: TestDbService.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Override
public TestPojo extract(SQLiteConnection conn, SQLiteStatement stmt) throws Exception {
   TestPojo result = new TestPojo();
   result.key = stmt.columnString(0);
   result.value1 = stmt.columnLong(1);
   result.value2 = stmt.columnDouble(2);

   byte[] value3 = stmt.columnBlob(3);
   if (value3 == null) {
      value3 = new byte[0];
   }

   result.value3 = value3;
   return result;
}
 
Example 7
Source File: BackupUtils.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
@Override
public String extract(SQLiteConnection conn, SQLiteStatement stmt) throws Exception {
   return stmt.columnString(0);
}
 
Example 8
Source File: AttestationServer.java    From AttestationServer with MIT License 4 votes vote down vote up
private static Account verifySession(final HttpExchange exchange, final boolean end, byte[] requestTokenEncoded)
        throws IOException, SQLiteException {
    final String cookie = getCookie(exchange, "__Host-session");
    if (cookie == null) {
        exchange.sendResponseHeaders(403, -1);
        return null;
    }
    final String[] session = cookie.split("\\|", 2);
    if (session.length != 2) {
        clearCookie(exchange);
        exchange.sendResponseHeaders(403, -1);
        return null;
    }
    final long sessionId = Long.parseLong(session[0]);
    final byte[] cookieToken = Base64.getDecoder().decode(session[1]);

    if (requestTokenEncoded == null) {
        requestTokenEncoded = new byte[session[1].length()];
        final DataInputStream input = new DataInputStream(exchange.getRequestBody());
        try {
            input.readFully(requestTokenEncoded);
        } catch (final EOFException e) {
            clearCookie(exchange);
            exchange.sendResponseHeaders(403, -1);
            return null;
        }
    }
    final byte[] requestToken = Base64.getDecoder().decode(requestTokenEncoded);

    final SQLiteConnection conn = new SQLiteConnection(AttestationProtocol.ATTESTATION_DATABASE);
    try {
        open(conn, !end);

        final SQLiteStatement select = conn.prepare("SELECT cookieToken, requestToken, " +
                "expiryTime, username, subscribeKey, Accounts.userId, verifyInterval, alertDelay " +
                "FROM Sessions " +
                "INNER JOIN Accounts on Accounts.userId = Sessions.userId " +
                "WHERE sessionId = ?");
        select.bind(1, sessionId);
        if (!select.step() || !MessageDigest.isEqual(cookieToken, select.columnBlob(0)) ||
                !MessageDigest.isEqual(requestToken, select.columnBlob(1))) {
            clearCookie(exchange);
            exchange.sendResponseHeaders(403, -1);
            return null;
        }

        if (select.columnLong(2) < System.currentTimeMillis()) {
            clearCookie(exchange);
            exchange.sendResponseHeaders(403, -1);
            return null;
        }

        if (end) {
            final SQLiteStatement delete = conn.prepare("DELETE FROM Sessions " +
                    "WHERE sessionId = ?");
            delete.bind(1, sessionId);
            delete.step();
            delete.dispose();
        }

        return new Account(select.columnLong(5), select.columnString(3), select.columnBlob(4),
                select.columnInt(6), select.columnInt(7));
    } finally {
        conn.dispose();
    }
}
 
Example 9
Source File: SQLite3Table.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
@Override
public String extract(SQLiteConnection conn, SQLiteStatement stmt) throws Exception {
   return stmt.columnString(0);
}
 
Example 10
Source File: ConfigService.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
@Override
public KeyValue extract(SQLiteConnection conn, SQLiteStatement stmt) throws Exception {
   String key = stmt.columnString(0);
   String val = stmt.columnString(1);
   return new KeyValue(key,val);
}
 
Example 11
Source File: ConfigService.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
@Override
public ValueWithTime<String> extract(SQLiteConnection conn, SQLiteStatement stmt) throws Exception {
   return new ValueWithTime<String>(stmt.columnString(0), stmt.columnLong(1), stmt.columnLong(2));
}
 
Example 12
Source File: ConfigService.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
@Override
public String extract(SQLiteConnection conn, SQLiteStatement stmt) throws Exception {
   return stmt.columnString(0);
}
 
Example 13
Source File: Extractors.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
@Override
public KeyValuePair extract(SQLiteConnection conn, SQLiteStatement stmt) throws Exception {
   String key = stmt.columnString(CONFIG_ALL_KEY_COL);
   String val = stmt.columnString(CONFIG_ALL_VALUE_COL);
   return new KeyValuePair(key,val);
}
 
Example 14
Source File: Extractors.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
@Override
public String extract(SQLiteConnection conn, SQLiteStatement stmt) throws Exception {
   return stmt.columnString(CONFIG_NAME_COL);
}
 
Example 15
Source File: ReflexDao.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
@Override
public KeyValue extract(SQLiteConnection conn, SQLiteStatement stmt) throws Exception {
   String key = stmt.columnString(0);
   String val = stmt.columnString(1);
   return new KeyValue(key,val);
}
 
Example 16
Source File: ReflexDao.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
@Override
public KeyValue extract(SQLiteConnection conn, SQLiteStatement stmt) throws Exception {
   String key = stmt.columnString(0);
   String val = stmt.columnString(1);
   return new KeyValue(key,val);
}
 
Example 17
Source File: ReflexDao.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
@Override
public String extract(SQLiteConnection conn, SQLiteStatement stmt) throws Exception {
   return stmt.columnString(0);
}