public SqlJetEncoding getEncoding() throws SqlJetException { return getCursor().getCursorDb().getOptions().getEncoding(); }
public void pushState() throws SqlJetException { SqlJetKeyInfo keyInfo = null; if (index) { keyInfo = new SqlJetKeyInfo(); keyInfo.setEnc(btree.getDb().getOptions().getEncoding()); } ISqlJetBtreeCursor cursor = btree.getCursor(rootPage, write, index ? keyInfo : null); states.push(new State(cursor, keyInfo)); clearRecordCache(); adjustKeyInfo(); }
zData = sMem.z; SqlJetVdbeSerialType.serialGet(zData, aTypeColumn, pDest); pDest.enc = cursor.getCursorDb().getOptions().getEncoding();
public boolean checkKey(Object... key) throws SqlJetException { if (eof()) return false; final ISqlJetBtreeRecord rec = SqlJetBtreeRecord.getRecord(btree.getDb().getOptions().getEncoding(), key); final ISqlJetMemoryPointer keyRecord = rec.getRawRecord(); try { return 0 == keyCompare(keyRecord, getRecord().getRawRecord()); } finally { rec.release(); } }
public int compareKey(Object[] key) throws SqlJetException { if (eof()) { return 1; } final ISqlJetBtreeRecord rec = SqlJetBtreeRecord.getRecord(btree.getDb().getOptions().getEncoding(), key); final ISqlJetMemoryPointer keyRecord = rec.getRawRecord(); rec.release(); return keyCompare(keyRecord, getRecord().getRawRecord()); }
return Integer.valueOf(getOptions().getCacheSize()); } else if ("encoding".equals(name)) { return getOptions().getEncoding(); } else if ("legacy_file_format".equals(name)) { return getOptions().isLegacyFileFormat();
public int compareKeys(Object[] firstKey, Object[] lastKey) throws SqlJetException { final SqlJetEncoding encoding = btree.getDb().getOptions().getEncoding(); final ISqlJetBtreeRecord first = SqlJetBtreeRecord.getRecord(encoding, firstKey); final ISqlJetBtreeRecord last = SqlJetBtreeRecord.getRecord(encoding, lastKey); final ISqlJetMemoryPointer firstRec = first.getRawRecord(); final ISqlJetMemoryPointer lastRec = last.getRawRecord(); final SqlJetUnpackedRecord unpacked = getKeyInfo().recordUnpack(firstRec.remaining(), firstRec); unpacked.getFlags().add(SqlJetUnpackedRecordFlags.PREFIX_MATCH); try { return unpacked.recordCompare(lastRec.remaining(), lastRec); } finally { unpacked.release(); first.release(); last.release(); } }
/** * @param key * @param value * @return * @throws SqlJetException */ public long put(long key, Object... values) throws SqlJetException { if (values != null) { final SqlJetEncoding encoding = mapDb.getOptions().getEncoding(); ISqlJetBtreeRecord record = SqlJetBtreeRecord.getRecord(encoding, values); final ISqlJetMemoryPointer pData = record.getRawRecord(); key = key > 0 ? key : newRowId(); insert(null, key, pData, pData.remaining(), 0, true); record.release(); return key; } else { if (goToKey(key)) { delete(); return key; } else { return 0; } } }
public void insert(long rowId, boolean append, Object... key) throws SqlJetException { lock(); try { final ISqlJetBtreeRecord rec = SqlJetBtreeRecord.getRecord(btree.getDb().getOptions().getEncoding(), SqlJetUtility.addArrays(key, new Object[] { rowId })); final ISqlJetMemoryPointer zKey = rec.getRawRecord(); getCursor().insert(zKey, zKey.remaining(), SqlJetUtility.allocatePtr(0), 0, 0, append); clearRecordCache(); rec.release(); } finally { unlock(); } }
/** * @param key * @return * @throws SqlJetException */ public boolean goToKey(Object[] key) throws SqlJetException { if (key != null && key.length > 0) { final SqlJetEncoding encoding = mapDb.getOptions().getEncoding(); final ISqlJetBtreeRecord rec = SqlJetBtreeRecord.getRecord(encoding, key); final ISqlJetMemoryPointer pKey = rec.getRawRecord(); rec.release(); final int moveTo = moveTo(pKey, pKey.remaining(), false); if (moveTo < 0 && !next()) { return false; } if (moveTo != 0) { final ISqlJetBtreeRecord record = getRecord(); if (null == record) { return false; } if (keyCompare(key.length, pKey, record.getRawRecord()) != 0) { return false; } } return true; } else { throw new SqlJetException("Key must be not null"); } }
final SqlJetEncoding encoding = btree.getDb().getOptions().getEncoding(); if (!tableDef.isRowIdPrimaryKey()) { final ISqlJetBtreeRecord rec = SqlJetBtreeRecord.getRecord(encoding, rowCompleted);
final SqlJetEncoding encoding = btree.getDb().getOptions().getEncoding(); ISqlJetBtreeRecord key = SqlJetBtreeRecord.getRecord(encoding, values); final ISqlJetMemoryPointer k = key.getRawRecord();
/** * @param row * @return * @throws SqlJetException */ private void doInsert(SqlJetConflictAction onConflict, final long rowId, final Object[] row) throws SqlJetException { final ISqlJetMemoryPointer pData; final SqlJetEncoding encoding = btree.getDb().getOptions().getEncoding(); if (!tableDef.isRowIdPrimaryKey()) { ISqlJetBtreeRecord rec = SqlJetBtreeRecord.getRecord(encoding, row); pData = rec.getRawRecord(); rec.release(); } else { final int primaryKeyColumnNumber = tableDef.getColumnNumber(tableDef.getRowIdPrimaryKeyColumnName()); if (primaryKeyColumnNumber == -1 || primaryKeyColumnNumber >= row.length) throw new SqlJetException(SqlJetErrorCode.ERROR); row[primaryKeyColumnNumber] = null; ISqlJetBtreeRecord rec = SqlJetBtreeRecord.getRecord(encoding, row); pData = rec.getRawRecord(); rec.release(); row[primaryKeyColumnNumber] = rowId; } if (doActionWithIndexes(Action.INSERT, onConflict, rowId, row)) { getCursor().insert(null, rowId, pData, pData.remaining(), 0, true); goToRow(rowId); } }
/** * @param key * @param value * @return * @throws SqlJetException */ public void put(Object[] key, Long value) throws SqlJetException { if (write) { if (value != null) { lock(); try { final SqlJetEncoding encoding = mapDb.getOptions().getEncoding(); final ISqlJetBtreeRecord rec = SqlJetBtreeRecord.getRecord(encoding, SqlJetUtility.addArrays(key, new Object[] { value })); final ISqlJetMemoryPointer zKey = rec.getRawRecord(); getCursor().insert(zKey, zKey.remaining(), SqlJetUtility.allocatePtr(0), 0, 0, true); clearRecordCache(); rec.release(); } finally { unlock(); } } else { if (goToKey(key)) { delete(); } } } else { throw new SqlJetException("Read-only"); } }
public boolean delete(long rowId, Object... key) throws SqlJetException { lock(); try { final ISqlJetBtreeRecord rec = SqlJetBtreeRecord.getRecord(btree.getDb().getOptions().getEncoding(), key); final ISqlJetMemoryPointer k = rec.getRawRecord(); rec.release(); if (cursorMoveTo(k, false) < 0) { next(); } do { final ISqlJetBtreeRecord record = getRecord(); if (null == record) return false; if (keyCompare(k, record.getRawRecord()) != 0) return false; if (getKeyRowId(record) == rowId) { getCursor().delete(); clearRecordCache(); if (cursorMoveTo(k, false) < 0) { next(); } return true; } } while (next()); return false; } finally { unlock(); } }