public CSqliteCopyResult(IDBResult res) { for( int i = 0; i < res.getColCount(); i++) m_arColumns.addElement(res.getColName(i)); for( ; !res.isEnd(); res.next() ) { m_arRows.addElement(res.getCurData()); } }
public CSqliteCopyResult(IDBResult res) { for (int i = 0; i < res.getColCount(); i++) { m_arColumns.addElement(res.getColName(i)); } for ( ; !res.isEnd(); res.next()) { m_arRows.addElement(res.getCurData()); } }
private void copyTable(String tableName, IDBStorage dbFrom, IDBStorage dbTo) { IDBResult res = dbFrom.executeSQL("SELECT * from " + tableName, null, false, false); String strInsert = ""; for ( ; !res.isEnd(); res.next()) { if (strInsert.length() == 0) { strInsert = createInsertStatement(res, tableName); } dbTo.executeSQL(strInsert, res.getCurData(), false, false); } }
public string[] getAllTableNames() { IDBResult res = executeSQL("SELECT name FROM sqlite_master WHERE type='table'", null, false, false); Vector <Object> arTables = new Vector <Object>(); for (; !res.isEnd(); res.next()) { arTables.addElement(res.getCurData()[0]); } String[] vecTables = new String[arTables.size()]; for (int i = 0; i < arTables.size(); i++) { vecTables[i] = (String)arTables.elementAt(i); } return(vecTables); }
void checkDBVersion() { DBVersion dbNewVer = new DBVersion(); dbNewVer.m_strRhoVer = RhoRuby.getRhoDBVersion(); dbNewVer.m_strAppVer = RhoConf.getInstance().getString("app_db_version"); String strEncryptionInfo = getEncryptionInfo(); dbNewVer.m_bEncrypted = strEncryptionInfo != null && strEncryptionInfo.length() > 0; dbNewVer.m_bSqlite = true; DBVersion dbVer = new DBVersion(); dbVer.fromFile(m_strDbVerPath); if (dbVer.m_strRhoVer.length() == 0) { dbNewVer.toFile(m_strDbVerPath); return; } boolean bRhoReset = dbVer.isRhoVerChanged(dbNewVer); boolean bAppReset = dbVer.isAppVerChanged(dbNewVer); boolean bDbFormatChanged = dbVer.isDbFormatChanged(dbNewVer); if (!bDbFormatChanged && dbVer.m_bEncrypted) { //TODO: check encryption key //if (!com.rho.RhoCrypto.isKeyExist(strEncryptionInfo) ) // bDbFormatChanged = true; } if (bDbFormatChanged) { LOG.INFO("Reset Database( format changed ):" + m_strDBPath); } if (bRhoReset && !bAppReset && !bDbFormatChanged) { bRhoReset = !migrateDB(dbVer, dbNewVer); } if (bRhoReset || bAppReset || bDbFormatChanged) { if (!bDbFormatChanged) { IDBStorage db = null; try { db = RhoClassFactory.createDBStorage(); if (db.isDbFileExists(m_strDBPath)) { db.open(m_strDBPath, "", strEncryptionInfo); IDBResult res = db.executeSQL("SELECT * FROM client_info", null, false, false); if (!res.isEnd()) { m_strClientInfoInsert = createInsertStatement(res, "client_info"); m_dataClientInfo = res.getCurData(); } } }catch (Exception exc) { LOG.ERROR("Copy client_info table failed.", exc); }finally { if (db != null) { try { db.close(); } catch (Exception) { } } } } m_dbStorage.deleteAllFiles(m_strDBPath); if (this.m_strDbPartition.compareTo("user") == 0) //do it only once { String fName = makeBlobFolderName(); CRhoFile.deleteDirectory(fName); makeBlobFolderName(); //Create folder back } dbNewVer.toFile(m_strDbVerPath); if (RhoConf.getInstance().isExist("bulksync_state") && RhoConf.getInstance().getInt("bulksync_state") != 0) { RhoConf.getInstance().setInt("bulksync_state", 0, true); } } }
private void processDelete(String tableName, IDBResult rows2Delete, int[] cols) { if (tableName.equalsIgnoreCase("changed_values") || tableName.equalsIgnoreCase("sources") || tableName.equalsIgnoreCase("client_info")) { return; } boolean bProcessTable = tableName.equalsIgnoreCase("object_values"); boolean bSchemaSrc = false; int nSrcID = 0; if (!bProcessTable) { nSrcID = m_db.getAttrMgr().getSrcIDHasBlobsByName(tableName); bProcessTable = nSrcID != 0; bSchemaSrc = bProcessTable; } if (!bProcessTable) { return; } if (!bSchemaSrc && !isChangedCol(cols, 3)) //value { return; } for ( ; !rows2Delete.isEnd(); rows2Delete.next()) { if (!bSchemaSrc) { nSrcID = rows2Delete.getIntByIdx(0); String attrib = rows2Delete.getStringByIdx(1); String value = rows2Delete.getStringByIdx(3); //if (cols == null) //delete // m_db.getAttrMgr().remove(nSrcID, attrib); if (m_db.getAttrMgr().isBlobAttr(nSrcID, attrib)) { processBlobDelete(nSrcID, attrib, value); } } else { Object[] data = rows2Delete.getCurData(); for (int i = 0; i < rows2Delete.getColCount(); i++) { if (!isChangedCol(cols, i)) { continue; } String attrib = rows2Delete.getColName(i); if (!(data[i] is String)) { continue; } String value = (String)data[i]; if (m_db.getAttrMgr().isBlobAttr(nSrcID, attrib)) { processBlobDelete(nSrcID, attrib, value); } } } } }
private void processDelete(String tableName, IDBResult rows2Delete, int[] cols) { if ( tableName.equalsIgnoreCase("changed_values") || tableName.equalsIgnoreCase("sources") || tableName.equalsIgnoreCase("client_info")) return; boolean bProcessTable = tableName.equalsIgnoreCase("object_values"); boolean bSchemaSrc = false; int nSrcID = 0; if ( !bProcessTable ) { nSrcID = m_db.getAttrMgr().getSrcIDHasBlobsByName(tableName); bProcessTable = nSrcID != 0; bSchemaSrc = bProcessTable; } if ( !bProcessTable) return; if ( !bSchemaSrc && !isChangedCol(cols, 3))//value return; for( ; !rows2Delete.isEnd(); rows2Delete.next() ) { if ( !bSchemaSrc ) { nSrcID = rows2Delete.getIntByIdx(0); String attrib = rows2Delete.getStringByIdx(1); String value = rows2Delete.getStringByIdx(3); //if (cols == null) //delete // m_db.getAttrMgr().remove(nSrcID, attrib); if ( m_db.getAttrMgr().isBlobAttr(nSrcID, attrib) ) processBlobDelete(nSrcID, attrib, value); }else { Object[] data = rows2Delete.getCurData(); for ( int i = 0; i < rows2Delete.getColCount(); i++ ) { if (!isChangedCol(cols, i)) continue; String attrib = rows2Delete.getColName(i); if ( !(data[i] is String ) ) continue; String value = (String)data[i]; if ( m_db.getAttrMgr().isBlobAttr(nSrcID, attrib) ) processBlobDelete(nSrcID, attrib, value); } } } }