使用 ODBC 检查列是否自动递增
Check if a column is auto increment with ODBC?
有没有办法知道使用C++和ODBC API是否具有具有自动序列属性(AKA标识属性)的列?
提前致谢
您可以使用
SQLSpecialColumns
函数。它提供了一个列列表,当事务更新行中的任何值时,这些列会自动更新。
>您可以将 SQLColAttribute 与字段标识符参数一起使用SQL_DESC_AUTO_UNIQUE_VALUE如在此函数中
int fetch_identity(const std::string& sql, int& is_identity)
{
SQLHSTMT hstmt;
is_identity = 0;
SQLCHAR colname[32]; // column name
SQLSMALLINT coltype; // column type
SQLSMALLINT colnamelen; // length of column name
SQLSMALLINT nullable; // whether column can have NULL value
SQLULEN collen; // column length
SQLSMALLINT decimaldigits; // no of digits if column is numeric
SQLLEN auto_unique_value;;
SQLINTEGER idx;
SQLSMALLINT nbr_cols;
if (!SQL_SUCCEEDED(SQLAllocHandle(SQL_HANDLE_STMT, query.m_hdbc, &hstmt)))
{
}
if (!SQL_SUCCEEDED(SQLPrepare(hstmt, (SQLCHAR*)sql.c_str(), SQL_NTS)))
{
extract_error(hstmt, SQL_HANDLE_STMT);
}
// Get number of nbr_cols from prepared statement
if (!SQL_SUCCEEDED(SQLNumResultCols(hstmt, &nbr_cols)))
{
extract_error(hstmt, SQL_HANDLE_STMT);
}
for (idx = 0; idx < nbr_cols; idx++)
{
// for each column from the prepared statement in hstmt, get the
// column name, type, column size, decimal digits, and nullability
if (!SQL_SUCCEEDED(SQLDescribeCol(hstmt,
(SQLUSMALLINT)idx + 1,
colname,
sizeof(colname),
&colnamelen,
&coltype,
&collen,
&decimaldigits,
&nullable)))
{
extract_error(hstmt, SQL_HANDLE_STMT);
}
auto_unique_value = 0;
//SQL_DESC_AUTO_UNIQUE_VALUE
//FieldIdentifier parameter returned in NumericAttributePtr
//SQL_TRUE if the column is an autoincrementing column.
//SQL_FALSE if the column is not an autoincrementing column or is not numeric.
if (!SQL_SUCCEEDED(SQLColAttribute(hstmt,
(SQLUSMALLINT)idx + 1,
SQL_DESC_AUTO_UNIQUE_VALUE,
NULL,
0,
NULL,
&auto_unique_value)))
{
extract_error(hstmt, SQL_HANDLE_STMT);
}
if (auto_unique_value == 1)
{
is_identity = 1;
}
}
SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
return 0;
}
变量m_hdbc在此处描述
https://github.com/pedro-vicente/lib_odbc
相关文章:
- 在提升multi_index容器中,是否定义了"default index"?
- 在C++STL中是否有Polyval(Matlab函数)等价物?
- 检查输入是否不是整数或数字
- 是否可以初始化不可复制类型的成员变量(或基类)
- 在C++中,是否可以基于给定的标识符创建基类的新实例,反之亦然
- 是否可以通过C++扩展强制多个python进程共享同一内存
- 此代码是否违反一个定义规则
- 是否需要删除包含对象的"pair"?
- 是否可以从int转换为enum类类型
- 无论条件是否为true,if总是在c++中执行
- 如何找到大小'x'数组是否完全填充,在C++?
- 检查值是否在集合p1和p2中,但不在p3中
- 是否可以在编译时初始化数组,以便在运行时不会花费时间?
- 检查 std::shared_ptr<> 的当前底层类型是否为 T
- 在c++中检查长方体是否尽可能快地重叠(无迭代)
- GL_SHADERSTORAGE_BUFFER位置是否与其他着色器位置冲突
- 子目录是否继承属性,例如add_definitions,include_directories和父Cmakelist.t
- C++ODBC检查连接是否成功
- Oracle 11gR1或R2客户端上是否设置了在ODBC API调用中将SELECT COUNT(*)返回的数据类型从
- 使用 ODBC 检查列是否自动递增