/** * Wrap a SQL exception that occurred while accessing a linked table. * * @param sql the SQL statement * @param ex the exception from the remote database * @return the wrapped exception */ public static DbException wrapException(String sql, Exception ex) { SQLException e = DbException.toSQLException(ex); return DbException.get(ErrorCode.ERROR_ACCESSING_LINKED_TABLE_2, e, sql, e.toString()); }
/** * Searches from the full text index for this database. * The returned result set has the following column: * <ul><li>QUERY (varchar): the query to use to get the data. * The query does not include 'SELECT * FROM '. Example: * PUBLIC.TEST WHERE ID = 1 * </li><li>SCORE (float) the relevance score. This value is always 1.0 * for the native fulltext search. * </li></ul> * * @param conn the connection * @param text the search query * @param limit the maximum number of rows or 0 for no limit * @param offset the offset or 0 for no offset * @return the result set */ public static ResultSet search(Connection conn, String text, int limit, int offset) throws SQLException { try { return search(conn, text, limit, offset, false); } catch (DbException e) { throw DbException.toSQLException(e); } }
/** * Searches from the full text index for this database. The result contains * the primary key data as an array. The returned result set has the * following columns: * <ul> * <li>SCHEMA (varchar): the schema name. Example: PUBLIC </li> * <li>TABLE (varchar): the table name. Example: TEST </li> * <li>COLUMNS (array of varchar): comma separated list of quoted column * names. The column names are quoted if necessary. Example: (ID) </li> * <li>KEYS (array of values): comma separated list of values. Example: (1) * </li> * <li>SCORE (float) the relevance score. This value is always 1.0 * for the native fulltext search. * </li> * </ul> * * @param conn the connection * @param text the search query * @param limit the maximum number of rows or 0 for no limit * @param offset the offset or 0 for no offset * @return the result set */ public static ResultSet searchData(Connection conn, String text, int limit, int offset) throws SQLException { try { return search(conn, text, limit, offset, true); } catch (DbException e) { throw DbException.toSQLException(e); } }
/** * Dumps the contents of a database to a SQL script file. * * @param dir the directory * @param db the database name (null for all databases) */ public static void execute(String dir, String db) throws SQLException { try { new Recover().process(dir, db); } catch (DbException e) { throw DbException.toSQLException(e); } }
/** * Create a new server for the given service. * * @param service the service * @param args the command line arguments */ public Server(Service service, String... args) throws SQLException { verifyArgs(args); this.service = service; try { service.init(args); } catch (Exception e) { throw DbException.toSQLException(e); } }
/** * Backs up database files. * * @param zipFileName the name of the target backup file (including path) * @param directory the source directory name * @param db the source database name (null if there is only one database, * and and empty string to backup all files in this directory) * @param quiet don't print progress information */ public static void execute(String zipFileName, String directory, String db, boolean quiet) throws SQLException { try { new Backup().process(zipFileName, directory, db, quiet); } catch (Exception e) { throw DbException.toSQLException(e); } }
@Override public void runTool(String... args) throws SQLException { String zipFileName = "backup.zip"; String dir = "."; String db = null; boolean quiet = false; for (int i = 0; args != null && i < args.length; i++) { String arg = args[i]; if (arg.equals("-dir")) { dir = args[++i]; } else if (arg.equals("-db")) { db = args[++i]; } else if (arg.equals("-quiet")) { quiet = true; } else if (arg.equals("-file")) { zipFileName = args[++i]; } else if (arg.equals("-help") || arg.equals("-?")) { showUsage(); return; } else { showUsageAndThrowUnsupportedOption(arg); } } try { process(zipFileName, dir, db, quiet); } catch (Exception e) { throw DbException.toSQLException(e); } }
/** * Change the whitespace characters. The whitespace characters are used to * separate words. If indexes already exist at the time this list is * changed, reindex must be called. * * @param conn the connection * @param whitespaceChars the list of characters */ public static void setWhitespaceChars(Connection conn, String whitespaceChars) throws SQLException { try { init(conn); FullTextSettings setting = FullTextSettings.getInstance(conn); setting.setWhitespaceChars(whitespaceChars); PreparedStatement prep = conn.prepareStatement("MERGE INTO " + SCHEMA + ".SETTINGS VALUES(?, ?)"); prep.setString(1, "whitespaceChars"); prep.setString(2, whitespaceChars); prep.execute(); } catch (DbException e) { throw DbException.toSQLException(e); } }
/** * Change the ignore list. The ignore list is a comma separated list of * common words that must not be indexed. The default ignore list is empty. * If indexes already exist at the time this list is changed, reindex must * be called. * * @param conn the connection * @param commaSeparatedList the list */ public static void setIgnoreList(Connection conn, String commaSeparatedList) throws SQLException { try { init(conn); FullTextSettings setting = FullTextSettings.getInstance(conn); setIgnoreList(setting, commaSeparatedList); Statement stat = conn.createStatement(); stat.execute("TRUNCATE TABLE " + SCHEMA + ".IGNORELIST"); PreparedStatement prep = conn.prepareStatement("INSERT INTO " + SCHEMA + ".IGNORELIST VALUES(?)"); prep.setString(1, commaSeparatedList); prep.execute(); } catch (DbException e) { throw DbException.toSQLException(e); } }
/** * Changes the password for a database. The passwords must be supplied as * char arrays and are cleaned in this method. The database must be closed * before calling this method. * * @param dir the directory (. for the current directory) * @param db the database name (null for all databases) * @param cipher the cipher (AES) * @param decryptPassword the decryption password as a char array * @param encryptPassword the encryption password as a char array * @param quiet don't print progress information */ public static void execute(String dir, String db, String cipher, char[] decryptPassword, char[] encryptPassword, boolean quiet) throws SQLException { try { new ChangeFileEncryption().process(dir, db, cipher, decryptPassword, encryptPassword, quiet); } catch (Exception e) { throw DbException.toSQLException(e); } }
throw DbException.toSQLException(e); throw DbException.toSQLException(e);
process(dir, db, cipher, decryptPassword, encryptPassword, quiet); } catch (Exception e) { throw DbException.toSQLException(e);
/** * Open a database connection. * This method should not be called by an application. * Instead, the method DriverManager.getConnection should be used. * * @param url the database URL * @param info the connection properties * @return the new connection or null if the URL is not supported */ @Override public Connection connect(String url, Properties info) throws SQLException { try { if (info == null) { info = new Properties(); } if (!acceptsURL(url)) { return null; } if (url.equals(DEFAULT_URL)) { return DEFAULT_CONNECTION.get(); } Connection c = DbUpgrade.connectOrUpgrade(url, info); if (c != null) { return c; } return new JdbcConnection(url, info); } catch (Exception e) { throw DbException.toSQLException(e); } }
throw DbException.toSQLException(e);
throw DbException.toSQLException(e);
/** * Log an exception and convert it to a SQL exception if required. * * @param ex the exception * @return the SQL exception object */ protected SQLException logAndConvert(Throwable ex) { SQLException e = null; try { e = DbException.toSQLException(ex); if (trace == null) { DbException.traceThrowable(e); } else { int errorCode = e.getErrorCode(); if (errorCode >= 23000 && errorCode < 24000) { trace.info(e, "exception"); } else { trace.error(e, "exception"); } } } catch(Throwable ignore) { if (e == null) { e = new SQLException("", "HY000", ex); } e.addSuppressed(ignore); } return e; }
e.printStackTrace(out); } else { throw DbException.toSQLException(e);
/** * Tries to start the server. * @return the server if successful * @throws SQLException if the server could not be started */ public Server start() throws SQLException { try { started = true; service.start(); String name = service.getName() + " (" + service.getURL() + ")"; Thread t = new Thread(this, name); t.setDaemon(service.isDaemon()); t.start(); for (int i = 1; i < 64; i += i) { wait(i); if (isRunning(false)) { return this; } } if (isRunning(true)) { return this; } throw DbException.get(ErrorCode.EXCEPTION_OPENING_PORT_2, name, "timeout; " + "please check your network configuration, specially the file /etc/hosts"); } catch (DbException e) { throw DbException.toSQLException(e); } }
private void sendErrorResponse(Exception re) throws IOException { SQLException e = DbException.toSQLException(re); server.traceError(e); startMessage('E'); write('S'); writeString("ERROR"); write('C'); writeString(e.getSQLState()); write('M'); writeString(e.getMessage()); write('D'); writeString(e.toString()); write(0); sendMessage(); }
throw DbException.toSQLException(e); } finally { if (script != null) {