Package org.tmatesoft.sqljet.core.internal

Examples of org.tmatesoft.sqljet.core.internal.ISqlJetBtreeCursor


        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();
    }
View Full Code Here


                    SqlJetUtility.of(SqlJetFileOpenPermission.READONLY));
            try {
                btree.beginTrans(SqlJetTransactionMode.READ_ONLY);
                final int pageCount = btree.getPager().getPageCount();
                for (int i = 1; i <= pageCount; i++) {
                    final ISqlJetBtreeCursor c = btree.getCursor(i, false, null);
                    c.enterCursor();
                    try {
                        final short flags = c.flags();
                        boolean intKey = SqlJetBtreeTableCreateFlags.INTKEY.hasFlag(flags);
                        if (!intKey)
                            continue;
                        logger.info("table " + i);
                        if (c.first()) {
                            logger.info("empty");
                        } else {
                            do {
                                final long key = c.getKeySize();
                                final int dataSize = c.getDataSize();
                                ISqlJetMemoryPointer data = SqlJetUtility.allocatePtr(dataSize);
                                c.data(0, dataSize, data);
                                final String str = SqlJetUtility.toString(data, SqlJetEncoding.UTF8).replaceAll(
                                        "[^\\p{Print}]", "?");
                                logger.info("record " + key + " : \"" + str + "\"");
                            } while (!c.next());
                        }
                    } finally {
                        c.leaveCursor();
                    }
                }
            } finally {
                btree.close();
            }
View Full Code Here

            try {
                btree.beginTrans(SqlJetTransactionMode.WRITE);
                for (int x = 1; x <= 3; x++) {
                    final int table = btree.createTable(SqlJetUtility.of(SqlJetBtreeTableCreateFlags.INTKEY,
                            SqlJetBtreeTableCreateFlags.LEAFDATA));
                    final ISqlJetBtreeCursor c = btree.getCursor(table, true, null);
                    c.enterCursor();
                    try {
                        for (int y = 1; y <= 3; y++) {
                            c.insert(null, y, pData, pData.remaining(), 0, false);
                        }
                        c.closeCursor();
                    } finally {
                        c.leaveCursor();
                    }
                }
                btree.commit();
            } finally {
                btree.close();
            }

            btree.open(testTempFile, db, btreeFlags, SqlJetFileType.MAIN_DB, fileFlags);
            try {
                final int pageCount = btree.getPager().getPageCount();
                for (int i = 1; i <= pageCount; i++) {
                    final ISqlJetBtreeCursor c = btree.getCursor(i, false, null);
                    c.enterCursor();
                    try {
                        if (!c.first()) {
                            logger.info("table " + i);
                            do {
                                StringBuilder s = new StringBuilder();
                                final long key = c.getKeySize();
                                if (key != 0)
                                    s.append("record ").append(key).append(" : ");
                                final int dataSize = c.getDataSize();
                                if (dataSize > 0) {
                                    ISqlJetMemoryPointer b = SqlJetUtility.allocatePtr(dataSize);
                                    c.data(0, dataSize, b);
                                    final String str = SqlJetUtility.toString(b, SqlJetEncoding.UTF8);
                                    s.append("\"").append(str.replaceAll("[^\\p{Print}]", "?")).append("\"");
                                    Assert.assertEquals(data, str);
                                }
                                if (s.length() > 0)
                                    logger.info(s.toString());
                            } while (!c.next());
                        }
                    } finally {
                        c.leaveCursor();
                    }
                }
            } finally {
                btree.close();
            }
View Full Code Here

                final ISqlJetMemoryPointer pData = SqlJetUtility.wrapPtr(SqlJetUtility.getBytes("Test data"));
                btree.beginTrans(SqlJetTransactionMode.WRITE);
                for (int x = 1; x <= 3; x++) {
                    final int table = btree.createTable(SqlJetUtility.of(SqlJetBtreeTableCreateFlags.INTKEY,
                            SqlJetBtreeTableCreateFlags.LEAFDATA));
                    final ISqlJetBtreeCursor c = btree.getCursor(table, true, null);
                    c.enterCursor();
                    try {
                        for (int y = 1; y <= 3; y++) {
                            c.insert(null, y, pData, pData.remaining(), 0, false);
                        }
                        c.closeCursor();
                    } finally {
                        c.leaveCursor();
                    }
                }
                btree.commit();
            } finally {
                btree.close();
            }

            btree.open(testTempFile, db, btreeFlags, SqlJetFileType.MAIN_DB, fileFlags);
            try {
                btree.beginTrans(SqlJetTransactionMode.WRITE);
                final int pageCount = btree.getPager().getPageCount();
                for (int x = 1; x <= pageCount; x++) {
                    final ISqlJetBtreeCursor c = btree.getCursor(x, true, null);
                    c.enterCursor();
                    try {
                        if (!c.first()) {
                            do {
                                c.delete();
                            } while (!c.eof());
                        }
                    } finally {
                        c.leaveCursor();
                    }
                }
                btree.commit();
            } finally {
                btree.close();
            }

            btree.open(testTempFile, db, SqlJetUtility.of(SqlJetBtreeFlags.READONLY), SqlJetFileType.MAIN_DB,
                    SqlJetUtility.of(SqlJetFileOpenPermission.READONLY));
            try {
                btree.beginTrans(SqlJetTransactionMode.READ_ONLY);
                final int pageCount = btree.getPager().getPageCount();
                for (int i = 1; i <= pageCount; i++) {
                    final ISqlJetBtreeCursor c = btree.getCursor(i, false, null);
                    c.enterCursor();
                    try {
                        final short flags = c.flags();
                        boolean intKey = SqlJetBtreeTableCreateFlags.INTKEY.hasFlag(flags);
                        if (!intKey)
                            continue;
                        logger.info("table " + i);
                        if (c.first()) {
                            logger.info("empty");
                        } else {
                            do {
                                final long key = c.getKeySize();
                                final int dataSize = c.getDataSize();
                                ISqlJetMemoryPointer data = SqlJetUtility.allocatePtr(dataSize);
                                c.data(0, dataSize, data);
                                final String str = SqlJetUtility.toString(data, SqlJetEncoding.UTF8).replaceAll(
                                        "[^\\p{Print}]", "?");
                                logger.info("record " + key + " : \"" + str + "\"");
                            } while (!c.next());
                        }
                    } finally {
                        c.leaveCursor();
                    }
                }
            } finally {
                btree.close();
            }
View Full Code Here

            try {
                btree.beginTrans(SqlJetTransactionMode.WRITE);
                for (int x = 1; x <= 3; x++) {
                    final int table = btree.createTable(SqlJetUtility.of(SqlJetBtreeTableCreateFlags.INTKEY,
                            SqlJetBtreeTableCreateFlags.LEAFDATA));
                    final ISqlJetBtreeCursor c = btree.getCursor(table, true, null);
                    c.enterCursor();
                    try {
                        for (int y = 1; y <= 3; y++) {
                            c.insert(null, y, pData, pData.remaining(), 0, false);
                        }
                        c.closeCursor();
                    } finally {
                        c.leaveCursor();
                    }
                }
                btree.commit();
            } finally {
                btree.close();
            }

            data = "Data test";
            bytes = SqlJetUtility.getBytes(data);
            pData = SqlJetUtility.wrapPtr(bytes);

            btree.open(testTempFile, db, btreeFlags, SqlJetFileType.MAIN_DB, fileFlags);
            try {
                btree.beginTrans(SqlJetTransactionMode.WRITE);
                final int pageCount = btree.getPager().getPageCount();
                for (int x = 1; x <= pageCount; x++) {
                    final ISqlJetBtreeCursor c = btree.getCursor(x, true, null);
                    c.enterCursor();
                    try {
                        if (!c.first()) {
                            c.cacheOverflow();
                            do {
                                c.putData(0, pData.remaining(), pData);
                            } while (!c.next());
                        }
                    } finally {
                        c.leaveCursor();
                    }
                }
                btree.commit();
            } finally {
                btree.close();
            }

            btree.open(testTempFile, db, btreeFlags, SqlJetFileType.MAIN_DB, fileFlags);
            try {
                final int pageCount = btree.getPager().getPageCount();
                for (int i = 1; i <= pageCount; i++) {
                    final ISqlJetBtreeCursor c = btree.getCursor(i, false, null);
                    c.enterCursor();
                    try {
                        if (!c.first()) {
                            logger.info("table " + i);
                            do {
                                StringBuilder s = new StringBuilder();
                                final long key = c.getKeySize();
                                if (key != 0)
                                    s.append("record ").append(key).append(" : ");
                                final int dataSize = c.getDataSize();
                                if (dataSize > 0) {
                                    ISqlJetMemoryPointer b = SqlJetUtility.allocatePtr(dataSize);
                                    c.data(0, dataSize, b);
                                    final String str = SqlJetUtility.toString(b, SqlJetEncoding.UTF8);
                                    s.append("\"").append(str.replaceAll("[^\\p{Print}]", "?")).append("\"");
                                    Assert.assertEquals(data, str);
                                }
                                if (s.length() > 0)
                                    logger.info(s.toString());
                            } while (!c.next());
                        }
                    } finally {
                        c.leaveCursor();
                    }
                }
            } finally {
                btree.close();
            }
View Full Code Here

TOP

Related Classes of org.tmatesoft.sqljet.core.internal.ISqlJetBtreeCursor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.