void prepared_statement_t::_bind_date_time_parameter(size_t index, const ::sqlpp::chrono::microsecond_point* value, bool is_null) {
			if(_handle->debug) {
				std::cerr << "ODBC debug: binding date_time parameter"
				" at index: " << index << ", being " << (is_null ? std::string() : "not") << " null" << std::endl;
			}
			SQLLEN indPtr(is_null ? SQL_NULL_DATA : 0);
			SQL_TIMESTAMP_STRUCT ts_value = {0};
			if(!is_null) {
				const auto dp = ::date::floor<::date::days>(*value);
				const auto time = date::make_time(*value - dp);
				const auto ymd = ::date::year_month_day{dp};
				ts_value.year = static_cast<int>(ymd.year());
				ts_value.month = static_cast<unsigned>(ymd.month());
				ts_value.day = static_cast<unsigned>(ymd.day());
				ts_value.hour = time.hours().count();
				ts_value.minute = time.minutes().count();
				ts_value.second = time.seconds().count();
				ts_value.fraction = time.subseconds().count();
			}
			
			auto rc = SQLBindParameter(_handle->stmt, 
									   index, 
									   SQL_PARAM_INPUT, 
									   SQL_C_TYPE_TIMESTAMP, 
									   SQL_TYPE_TIMESTAMP, 
									   sizeof(SQL_TIMESTAMP_STRUCT),
									   0, 
									   (SQLPOINTER)&ts_value, 
									   sizeof(SQL_DATE_STRUCT), 
									   &indPtr);
			if(rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
				throw sqlpp::exception("ODBC error: couldn't bind date parameter: "+detail::odbc_error(_handle->stmt, SQL_HANDLE_STMT));
			}
		}
示例#2
0
  // This teebuf has no buffer. So every character "overflows"
  // and can be put directly into the teed buffers.
  virtual int overflow(int c)
  {
    // if previous char was newline, print timestamp now.
    if (mNewLine && arg_timestamp) {
      char buffer[32];
      auto const now = std::chrono::system_clock::now();
      auto const dp = floor<date::days>(now);
      auto const date = date::year_month_day(dp);
      auto const time = date::make_time(now-dp);

      int l = snprintf(buffer, sizeof(buffer) - 1, "%04d%02d%02d %02d:%02d:%02lld.%03lld| ", (const int) date.year(), (unsigned) date.month(), (unsigned) date.day(), time.hours().count(), time.minutes().count(), time.seconds().count(), std::chrono::duration_cast<std::chrono::milliseconds>(time.subseconds()).count());

      mStreamBuf1->sputn(buffer, l);
      if (mStreamBuf2 != NULL)
        mStreamBuf2->sputn(buffer, l);
      mNewLine = false;
    }

    // check if this char is a newline.
    if (c == '\n')
      mNewLine = true;

    if (c == EOF)
    {
      return !EOF;
    }
    else
    {
      int const r1 = mStreamBuf1->sputc(c);
      int const r2 = (mStreamBuf2 != NULL) ? mStreamBuf2->sputc(c) : 0;
      return r1 == EOF || r2 == EOF ? EOF : c;
    }
  }