Search in sources :

Example 1 with MySQLTimeStatus

use of com.actiontech.dble.plan.common.time.MySQLTimeStatus in project dble by actiontech.

the class CmpUtil method getMysqlTimeFromStr.

/**
 * Parse date provided in a string to a MYSQL_TIME.
 *
 * @return Status flag
 * @param[in] thd Thread handle
 * @param[in] str A string to convert
 * @param[in] warn_type Type of the timestamp for issuing the warning
 * @param[in] warn_name Field name for issuing the warning
 * @param[out] l_time The MYSQL_TIME objects is initialized.
 * <p>
 * Parses a date provided in the string str into a MYSQL_TIME
 * object. If the string contains an incorrect date or doesn't
 * correspond to a date at all then a warning is issued. The
 * warn_type and the warn_name arguments are used as the name
 * and the type of the field when issuing the warning. If any
 * input was discarded (trailing or non-timestamp-y characters),
 * return value will be TRUE.
 * @retval FALSE Success.
 * @retval True Indicates failure.
 */
public static boolean getMysqlTimeFromStr(String str, MySQLTimestampType warnType, final String warnName, MySQLTime lTime) {
    boolean value;
    MySQLTimeStatus status = new MySQLTimeStatus();
    if (!MyTime.strToDatetime(str, str.length(), lTime, MyTime.TIME_FUZZY_DATE, status) && (lTime.getTimeType() == MySQLTimestampType.MYSQL_TIMESTAMP_DATETIME || lTime.getTimeType() == MySQLTimestampType.MYSQL_TIMESTAMP_DATE))
        /*
             * Do not return yet, we may still want to throw a
             * "trailing garbage" warning.
             */
        value = false;
    else {
        value = true;
        status.setWarnings(MyTime.MYSQL_TIME_WARN_TRUNCATED);
    /*
                                                                 * force warning
                                                                 */
    }
    return value;
}
Also used : MySQLTimeStatus(com.actiontech.dble.plan.common.time.MySQLTimeStatus)

Example 2 with MySQLTimeStatus

use of com.actiontech.dble.plan.common.time.MySQLTimeStatus in project dble by actiontech.

the class MySQLcom method getDateFromStr.

/**
 * @return converted value. 0 on error and on zero-dates -- check 'failure'
 * @brief Convert date provided in a string to its packed temporal int
 * representation.
 * @param[in] thd thread handle
 * @param[in] str a string to convert
 * @param[in] warn_type type of the timestamp for issuing the warning
 * @param[in] warn_name field name for issuing the warning
 * @param[out] error_arg could not extract a DATE or DATETIME
 * @details Convert date provided in the string str to the int
 * representation. If the string contains wrong date or doesn't
 * contain it at all then a warning is issued. The warn_type and
 * the warn_name arguments are used as the name and the type of the
 * field when issuing the warning.
 */
public static long getDateFromStr(String str, MySQLTimestampType warntype, BoolPtr error) {
    MySQLTime ltime = new MySQLTime();
    MySQLTimeStatus status = new MySQLTimeStatus();
    error.set(MyTime.strToDatetime(str, str.length(), ltime, MyTime.TIME_FUZZY_DATE, status));
    if (error.get())
        return 0;
    return MyTime.timeToLonglongDatetimePacked(ltime);
}
Also used : MySQLTime(com.actiontech.dble.plan.common.time.MySQLTime) MySQLTimeStatus(com.actiontech.dble.plan.common.time.MySQLTimeStatus)

Aggregations

MySQLTimeStatus (com.actiontech.dble.plan.common.time.MySQLTimeStatus)2 MySQLTime (com.actiontech.dble.plan.common.time.MySQLTime)1