/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ #pragma once
static DATE_STRUCT DateToOdbcDate(const css::util::Date& x)
{
DATE_STRUCT aVal;
aVal.year = x.Year;
aVal.month = x.Month;
aVal.day = x.Day; return aVal;
} static TIME_STRUCT TimeToOdbcTime(const css::util::Time& x)
{
TIME_STRUCT aVal;
aVal.hour = x.Hours;
aVal.minute = x.Minutes;
aVal.second = x.Seconds; return aVal;
} static TIMESTAMP_STRUCT DateTimeToTimestamp(const css::util::DateTime& x)
{
TIMESTAMP_STRUCT aVal;
aVal.year = x.Year;
aVal.month = x.Month;
aVal.day = x.Day;
aVal.hour = x.Hours;
aVal.minute = x.Minutes;
aVal.second = x.Seconds;
aVal.fraction = x.NanoSeconds; return aVal;
} /** getBindTypes set the ODBC type for C @param _bUseOldTimeDate true when the old datetime format should be used @param _nOdbcType the ODBC sql type @param fCType the C type for the ODBC type @param fSqlType the SQL type for the ODBC type
*/ staticvoid getBindTypes(bool _bUseOldTimeDate,
SQLSMALLINT _nOdbcType,
SQLSMALLINT& fCType,
SQLSMALLINT& fSqlType);
// A templated class to encapsulate conversion from our string types into arrays of // SQLCHAR / SQLWCHAR (non-const, even if used as input values, and not modified), // that ODBC functions take. It owns its buffer (important for delayed reads/writes)
template <typename C, size_t CHAR_SIZE = sizeof(C)> class CHARS {};
template <typename C> class CHARS<C, sizeof(sal_uInt32)> : public SIZED<sizeof(sal_uInt32)>
{ public:
CHARS() = default;
CHARS(std::u16string_view str)
{ auto size = std::min(str.size(), size_t(std::numeric_limits<SQLSMALLINT>::max()));
m_buf = std::make_unique<sal_uInt32[]>(size + 1); auto p = m_buf.get(); for (size_t i = 0; i < str.size() && o3tl::make_unsigned(p - m_buf.get()) < size; ++p)
*p = o3tl::iterateCodePoints(str, &i);
m_len = p - m_buf.get();
*p = 0;
} // Explicitly define a redundant overload for OUString to avoid certain loplugin warnings in // code prepared to work with SQLWCHAR being either 16-bit unsigned short (Linux) or 32-bit // wchar_t (macOS):
CHARS(OUString const & str): CHARS(static_cast<std::u16string_view>(str)) {}
C* get() { returnreinterpret_cast<C*>(m_buf.get()); }
private:
std::unique_ptr<sal_uInt32[]> m_buf;
};
using SQLChars = CHARS<SQLCHAR>; using SQLWChars = CHARS<SQLWCHAR>;
// for now, use wchar only on Windows (see comment in OPreparedStatement::setParameter) #ifdef _WIN32 constbool bUseWChar = true; #else constvolatileinlinebool bUseWChar = false; // volatile to avoid "unreachabe code" warnings #endif
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.