📄 library.java
字号:
if (d == null) { return null; } return ValuePool.getInt(HsqlDateTime.getDateTimePart(d, Calendar.WEEK_OF_YEAR)); } /** * Returns the year from the given date value, as an integer value in * the range of 1-9999. <p> * * @param d the date value from which to extract the year * @return an integer value representing the year from the given * date value */ public static Integer year(Date d) { if (d == null) { return null; } return ValuePool.getInt(HsqlDateTime.getDateTimePart(d, Calendar.YEAR)); } /** * @since 1.8.0 */ public static String to_char(java.util.Date d, String format) { if (d == null || format == null) { return null; } synchronized (tocharFormat) { tocharFormat.applyPattern(HsqlDateTime.toJavaDatePattern(format)); return tocharFormat.format(d); } } // date calculations. /** * Returns the number of units elapsed between two dates.<p> * The datapart parameter indicates the part to be used for computing the * difference. Supported types include: 'year', 'yy', 'month', 'mm' * 'day', 'dd', 'hour', 'hh', 'minute', 'mi', 'second', 'ss', 'millisecond', * 'ms'. * * Contributed by Michael Landon<p> * * @param datepart Specifies the unit in which the interval is to be measured. * @param d1 The starting datetime value for the interval. This value is * subtracted from d2 to return the number of * date-parts between the two arguments. * @param d2 The ending datetime for the interval. d1 is subtracted * from this value to return the number of date-parts * between the two arguments. * * since 1.7.3 */ public static Long datediff(String datepart, Timestamp d1, Timestamp d2) throws HsqlException { // make sure we've got valid data if (d1 == null || d2 == null) { return null; } if ("yy".equalsIgnoreCase(datepart) || "year".equalsIgnoreCase(datepart)) { return ValuePool.getLong(getElapsed(Calendar.YEAR, d1, d2)); } else if ("mm".equalsIgnoreCase(datepart) || "month".equalsIgnoreCase(datepart)) { return ValuePool.getLong(getElapsed(Calendar.MONTH, d1, d2)); } else if ("dd".equalsIgnoreCase(datepart) || "day".equalsIgnoreCase(datepart)) { return ValuePool.getLong(getElapsed(Calendar.DATE, d1, d2)); } else if ("hh".equalsIgnoreCase(datepart) || "hour".equalsIgnoreCase(datepart)) { return ValuePool.getLong(getElapsed(Calendar.HOUR, d1, d2)); } else if ("mi".equalsIgnoreCase(datepart) || "minute".equalsIgnoreCase(datepart)) { return ValuePool.getLong(getElapsed(Calendar.MINUTE, d1, d2)); } else if ("ss".equalsIgnoreCase(datepart) || "second".equalsIgnoreCase(datepart)) { return ValuePool.getLong(getElapsed(Calendar.SECOND, d1, d2)); } else if ("ms".equalsIgnoreCase(datepart) || "millisecond".equalsIgnoreCase(datepart)) { return ValuePool.getLong(getElapsed(Calendar.MILLISECOND, d1, d2)); } else { throw Trace.error(Trace.INVALID_CONVERSION); } } /** * Private method used to do actual calculation units elapsed between * two given dates. <p> * * @param field Calendar field to use to calculate elapsed time * @param d1 The starting date for the interval. This value is * subtracted from d2 to return the number of * date-parts between the two arguments. * @param d2 The ending date for the interval. d1 is subtracted * from this value to return the number of date-parts * between the two arguments. */ private static long getElapsed(int field, java.util.Date d1, java.util.Date d2) { // can we do this very simply? if (field == Calendar.MILLISECOND) { return d2.getTime() - d1.getTime(); } // ok, let's work a little harder: Calendar g1 = Calendar.getInstance(), g2 = Calendar.getInstance(); g1.setTime(d1); g2.setTime(d2); g1.set(Calendar.MILLISECOND, 0); g2.set(Calendar.MILLISECOND, 0); if (field == Calendar.SECOND) { return (g2.getTime().getTime() - g1.getTime().getTime()) / 1000; } g1.set(Calendar.SECOND, 0); g2.set(Calendar.SECOND, 0); if (field == Calendar.MINUTE) { return (g2.getTime().getTime() - g1.getTime().getTime()) / (1000 * 60); } g1.set(Calendar.MINUTE, 0); g2.set(Calendar.MINUTE, 0); if (field == Calendar.HOUR) { return (g2.getTime().getTime() - g1.getTime().getTime()) / (1000 * 60 * 60); } // end if-else // if we got here, then we really need to work: long elapsed = 0; short sign = 1; if (g2.before(g1)) { sign = -1; Calendar tmp = g1; g1 = g2; g2 = tmp; } // end if g1.set(Calendar.HOUR_OF_DAY, 0); g2.set(Calendar.HOUR_OF_DAY, 0); if (field == Calendar.MONTH || field == Calendar.YEAR) { g1.set(Calendar.DATE, 1); g2.set(Calendar.DATE, 1); } if (field == Calendar.YEAR) { g1.set(Calendar.MONTH, 1); g2.set(Calendar.MONTH, 1); } // end if-else // then calculate elapsed units while (g1.before(g2)) { g1.add(field, 1); elapsed++; } return sign * elapsed; } // end getElapsed // SYSTEM /* * All system functions that return Session dependent information are * dummies here. */ /** * Returns the name of the database corresponding to this connection. * * @param conn the connection for which to retrieve the database name * @return the name of the database for the given connection * @throws HsqlException if a database access error occurs */ public static String database(Connection conn) throws HsqlException { return null; } /** * Returns the user's authorization name (the user's name as known to this * database). * * @param conn the connection for which to retrieve the user name * @return the user's name as known to the database * @throws HsqlException if a database access error occurs */ public static String user(Connection conn) throws HsqlException { return null; } /** * Retrieves the last auto-generated integer indentity value * used by this connection. <p> * * Dummy mehtod.<p> * * @return the connection's the last generated integer identity value * @throws HsqlException if a database access error occurs */ public static int identity() throws HsqlException { return 0; } // JDBC SYSTEM /** * Retrieves the autocommit status of this connection. <p> * * @param conn the <code>Connection</code> object for which to retrieve * the current autocommit status * @return a boolean value representing the connection's autocommit status * @since 1.7.0 */ public static boolean getAutoCommit(Connection conn) { return false; } /** * Retrieves the full version number of this database product. <p> * * @return database version number as a <code>String</code> object * @since 1.8.0.4 */ public static String getDatabaseFullProductVersion() { return HsqlDatabaseProperties.THIS_FULL_VERSION; } /** * Retrieves the name of this database product. <p> * * @return database product name as a <code>String</code> object * @since 1.7.2 */ public static String getDatabaseProductName() { return HsqlDatabaseProperties.PRODUCT_NAME; } /** * Retrieves the version number of this database product. <p> * * @return database version number as a <code>String</code> object * @since 1.7.2 */ public static String getDatabaseProductVersion() { return HsqlDatabaseProperties.THIS_VERSION; } /** * Retrieves the major version number of this database. <p> * * @return the database's major version as an <code>int</code> value * @since 1.7.2 */ public static int getDatabaseMajorVersion() { return HsqlDatabaseProperties.MAJOR; } /** * Retrieves the major version number of this database. <p> * * @return the database's major version as an <code>int</code> value * @since 1.7.2 */ public static int getDatabaseMinorVersion() { return HsqlDatabaseProperties.MINOR; } /** * Retrieves whether this connection is in read-only mode. <p> * * Dummy mehtod.<p> * * @param conn the <code>Connection</code> object for which to retrieve * the current read-only status * @return <code>true</code> if connection is read-only and * <code>false</code> otherwise * @since 1.7.2 */ public static boolean isReadOnlyConnection(Connection conn) { return false; } /** * Dummy method. Retrieves whether this database is in read-only mode. <p> * * @param c the <code>Connection</code> object for which to retrieve * the current database read-only status * @return <code>true</code> if so; <code>false</code> otherwise * @since 1.7.2 */ public static boolean isReadOnlyDatabase(Connection c) { return false; } /** * Retrieves whether the files of this database are in read-only mode. <p> * * Dummy mehtod.<p> * * @param c the <code>Connection</code> object for which to retrieve * the current database files read-only status * @return <code>true</code> if so; <code>false</code> otherwise * @since 1.7.2 */ public static boolean isReadOnlyDatabaseFiles(Connection c) { return false; } static final int abs = 0; static final int ascii = 1; static final int bitand = 2; static final int bitLength = 3; static final int bitor = 4; static final int bitxor = 5; static final int character = 6; static final int concat = 7; static final int cot = 8; static final int curdate = 9; static final int curtime = 10; static final int database = 11; static final int datediff = 12; static final int day = 13; static final int dayname = 14; static final int dayofmonth = 15; static final int dayofweek = 16; static final int dayofyear = 17; static final int difference = 18; static final int getAutoCommit = 19; static final int getDatabaseFullProductVersion = 20; static final int getDatabaseMajorVersion = 21; static final int getDatabaseMinorVersion = 22; static final int getDatabaseProductName = 23; static final int getDatabaseProductVersion = 24; static final int hexToRaw = 25; static final int hour = 26; static final int identity = 27; static final int insert = 28; static final int isReadOnlyConnection = 29; static final int isReadOnlyDatabase = 30; static final int isReadOnlyDatabaseFiles = 31; static final int lcase = 32; static final int left = 33; static final int length = 34; static final int locate = 35; static final int log10 = 36; static final int ltrim = 37; static final int minute = 38; static final int mod = 39; static final int month = 40; static final int monthname = 41; static final int now = 42; static final int octetLength = 43; static final int pi = 44; static final int position = 45; static final int quarter = 46; static final int rand = 47; static final int rawToHex = 48; static final int repeat = 49; static final int replace = 50; static final int right = 51; static final int round = 52; static final int roundMagic = 53; stati
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -