⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 types.h

📁 絲路server源碼 Silk Road server source
💻 H
📖 第 1 页 / 共 2 页
字号:
    }    /** Sets the day of this date */    void setDay(int day) {      day_=this->_validateDay(day);    }    /** Gets the date as a string in the <tt>YYYY-MM-DD</tt> format */    virtual ODBCXX_STRING toString() const;  };  /** An SQL TIME */  class ODBCXX_EXPORT Time {  protected:    int hour_;    int minute_;    int second_;    virtual void _invalid(const ODBCXX_CHAR_TYPE* what, int value);    int _validateHour(int h) {      if(h<0 || h>23) {        this->_invalid(ODBCXX_STRING_CONST("hour"),h);      }      return h;    }    int _validateMinute(int m) {      if(m<0 || m>59) {        this->_invalid(ODBCXX_STRING_CONST("minute"),m);      }      return m;    }    int _validateSecond(int s) {      if(s<0 || s>61) {        this->_invalid(ODBCXX_STRING_CONST("second"),s);      }      return s;    }  public:    /** Constructor */    Time(int hour, int minute, int second) {      this->setHour(hour);      this->setMinute(minute);      this->setSecond(second);    }    /** Constructor.     *     * Sets the time to now.     */    explicit Time();    /** Constructor.     *     * Sets the time to the specified <tt>time_t</tt> value.     */    Time(std::time_t t) {      this->setTime(t);    }    /** Constructor.     *     * Sets the time to the specified string in the <tt>HH:MM:SS</tt> format.     */    Time(const ODBCXX_STRING& str) {      this->parse(str);    }    /** Copy constructor */    Time(const Time& t)      :hour_(t.hour_),       minute_(t.minute_),       second_(t.second_) {}    /** Assignment operator */    Time& operator=(const Time& t) {      hour_=t.hour_;      minute_=t.minute_;      second_=t.second_;      return *this;    }    /** Destructor */    virtual ~Time() {}    /** Sets the time to the specified <tt>time_t</tt> value */    virtual void setTime(std::time_t t);    /** Returns the <tt>time_t</tt> value of <tt>1970-01-01</tt> at this time */    std::time_t getTime() const;    /** Sets this time from a string in the <tt>HH:MM:SS</tt> format */    void parse(const ODBCXX_STRING& str);    /** Gets the hour of this time */    int getHour() const {      return hour_;    }    /** Gets the minute of this time */    int getMinute() const {      return minute_;    }    /** Gets the second of this time */    int getSecond() const {      return second_;    }    /** Sets the hour of this time */    void setHour(int h) {      hour_=this->_validateHour(h);    }    /** Sets the minute of this time */    void setMinute(int m) {      minute_=this->_validateMinute(m);    }    /** Sets the second of this time */    void setSecond(int s) {      second_=this->_validateSecond(s);    }    virtual ODBCXX_STRING toString() const;  };  /** An SQL TIMESTAMP   */  class ODBCXX_EXPORT Timestamp : public Date, public Time {  private:    int nanos_;    virtual void _invalid(const ODBCXX_CHAR_TYPE* what, int value);    int _validateNanos(int n) {      if(n<0) {        this->_invalid(ODBCXX_STRING_CONST("nanoseconds"),n);      }      return n;    }  public:    /** Constructor */    Timestamp(int year, int month, int day,              int hour, int minute, int second,              int nanos =0)      :Date(year,month,day), Time(hour,minute,second) {      this->setNanos(nanos);    }    /** Constructor.     *     * Sets the timestamp to now.     */    explicit Timestamp();    /** Constructor.     *     * Sets this timestamp to the specified <tt>time_t</tt> value.     */    Timestamp(std::time_t t) {      this->setTime(t);    }    /** Constructor.     *     * Sets this timestamp from a <tt>YYYY-MM-DD HH:MM:SS[.NNN...]</tt> format     */    Timestamp(const ODBCXX_STRING& s) {      this->parse(s);    }    /** Copy constructor */    Timestamp(const Timestamp& t)      :Date(t),Time(t),nanos_(t.nanos_) {}    /** Assignment operator */    Timestamp& operator=(const Timestamp& t) {      Date::operator=(t);      Time::operator=(t);      nanos_=t.nanos_;      return *this;    }    /** Destructor */    virtual ~Timestamp() {}    /** Sets this timestamp to the specified <tt>time_t</tt> value */    virtual void setTime(std::time_t t);    /** Gets the time_t value of this timestamp */    virtual std::time_t getTime() const {      return Date::getTime()+Time::getTime();    }    /** Set this timestamp from a <tt>YYYY-MM-DD HH:MM:SS[.NNN...]</tt> format     */    void parse(const ODBCXX_STRING& s);    /** Gets the nanoseconds value of this timestamp */    int getNanos() const {      return nanos_;    }    /** Sets the nanoseconds value of this timestamp */    void setNanos(int nanos) {      nanos_=this->_validateNanos(nanos);    }    virtual ODBCXX_STRING toString() const;  };  //this is used for several 'lists of stuff' below  //expects T to be a pointer-to-something, and  //the contents will get deleted when the vector  //itself is deleted  template <class T> class CleanVector : public std::vector<T> {  private:    CleanVector(const CleanVector<T>&); //forbid    CleanVector<T>& operator=(const CleanVector<T>&); //forbid  public:    explicit CleanVector() {}    virtual ~CleanVector() {      typename std::vector<T>::iterator i=this->begin();      typename std::vector<T>::iterator end=this->end();      while(i!=end) {        delete *i;        ++i;      }      this->clear();    }  };  /** Used internally - represents the result of an SQLError call   */  class ODBCXX_EXPORT DriverMessage {    friend class ErrorHandler;  private:    ODBCXX_CHAR_TYPE state_[SQL_SQLSTATE_SIZE+1];    ODBCXX_CHAR_TYPE description_[SQL_MAX_MESSAGE_LENGTH];    SQLINTEGER nativeCode_;    DriverMessage() {}#if ODBCVER < 0x0300    static DriverMessage* fetchMessage(SQLHENV henv,                                       SQLHDBC hdbc,                                       SQLHSTMT hstmt);#else    static DriverMessage* fetchMessage(SQLINTEGER handleType,                                       SQLHANDLE h,                                       int idx);#endif  public:    virtual ~DriverMessage() {}    const ODBCXX_CHAR_TYPE* getSQLState() const {      return state_;    }    const ODBCXX_CHAR_TYPE* getDescription() const {      return description_;    }    int getNativeCode() const {      return nativeCode_;    }  };  /** The exception thrown when errors occur inside the library.   */  class SQLException : public std::exception {  private:    ODBCXX_STRING reason_;    ODBCXX_STRING sqlState_;    int errorCode_;#if defined(ODBCXX_UNICODE)    std::string reason8_;#elif defined(ODBCXX_QT)    QCString reason8_;#endif  public:    /** Constructor */    SQLException(const ODBCXX_STRING& reason =ODBCXX_STRING_CONST(""),                 const ODBCXX_STRING& sqlState =ODBCXX_STRING_CONST(""),                 int vendorCode =0)      :reason_(reason),       sqlState_(sqlState),       errorCode_(vendorCode)#if defined(ODBCXX_UNICODE){   const size_t length =sizeof(wchar_t)*reason_.size();   char* temp =new char[length+1];   wcstombs(temp,reason_.c_str(),length);   reason8_ =temp;   delete[] temp;}#else# if defined(ODBCXX_QT)      ,reason8_(reason.local8Bit())# endif{}#endif    /** Copy from a DriverMessage */    SQLException(const DriverMessage& dm)      :reason_(dm.getDescription()),       sqlState_(dm.getSQLState()),       errorCode_(dm.getNativeCode()) {}    /** Destructor */    virtual ~SQLException() throw() {}    /** Get the vendor error code of this exception */    int getErrorCode() const {      return errorCode_;    }    /** Gets the SQLSTATE of this exception.     *     * Consult your local ODBC reference for SQLSTATE values.     */    const ODBCXX_STRING& getSQLState() const {      return sqlState_;    }    /** Gets the description of this message */    const ODBCXX_STRING& getMessage() const {      return reason_;    }    /** Gets the description of this message */    virtual const char* what() const throw() {      // the conversion from QString involves a temporary, which      // doesn't survive this scope. So here, we do a conditional#if defined(ODBCXX_QT)      return reason8_.data();#else# if defined(ODBCXX_UNICODE)      return reason8_.c_str();# else      return reason_.c_str();# endif#endif    }  };  /** Represents an SQL warning.   *   * Contains the same info as an SQLException.   */  class SQLWarning : public SQLException {    SQLWarning(const SQLWarning&); //forbid    SQLWarning& operator=(const SQLWarning&); //forbid  public:    /** Constructor */    SQLWarning(const ODBCXX_STRING& reason = ODBCXX_STRING_CONST(""),               const ODBCXX_STRING& sqlState = ODBCXX_STRING_CONST(""),               int vendorCode =0)      :SQLException(reason,sqlState,vendorCode) {}    /** Copy from a DriverMessage */    SQLWarning(const DriverMessage& dm)      :SQLException(dm) {}    /** Destructor */    virtual ~SQLWarning() throw() {}  };  typedef CleanVector<SQLWarning*> WarningList;  template <class T> class Deleter {  private:    T* ptr_;    bool isArray_;    Deleter(const Deleter<T>&);    Deleter<T>& operator=(const Deleter<T>&);  public:    explicit Deleter(T* ptr, bool isArray =false)      :ptr_(ptr), isArray_(isArray) {}    ~Deleter() {      if(!isArray_) {        delete ptr_;      } else {        delete[] ptr_;      }    }  };} // namespace odbc#endif // __ODBCXX_TYPES_H

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -