SQLBindFileToParam
SQLBindFileToParam#
SQLBindFileToParam binds the parameter market '?' used for LOB data type to a file or files. When SQLExecute() or SQLExecDirect() is called, data is transferred from the file(s) to the database management system.
Syntax#
SQLRETURN SQLBindFileToParam(
SQLHSTMT stmt,
SQLSMALLINT par,
SQLSMALLINT sqlType,
SQLCHAR * fileName,
SQLLEN * fileNameLength,
SQLUINTEGER * fileOptions,
SQLLEN maxFileNameLength,
SQLLEN * ind);
Arguments#
Data Type | Argument | In/Output | Description |
---|---|---|---|
SQLHSTMT | stmt | Input | A handle for the found results. |
SQLSMALLINT | Par | Input | The order of parameters. Begins at 1. |
SQLSMALLINT | sqlType | Input | The SQL data type of a parameter.The following options are available: SQL_BLOB SQL_CLOB |
SQLCHAR * | fileName | Input(Pending ) | A pointer to the buffer that holds a filename or an array of filenames. Upon SQLExecute() or SQLExecDirect(), there should be a filename stored in this buffer. Either of an absolute path (recommended) and a relative path is allowed. This argument cannot be NULL. |
SQLLEN * | fileNameLength | Input(Pending) | A pointer to the buffer that holds a filename length or an array of filename lengths.Upon SQLExecute() or SQLExecDirect(), there should be a filename length stored in this buffer.If this argument is NULL, a filename is regarded as a null-terminated string. That is, it has the same effect as if SQL_NTS were stored in the memory pointed by this argument.The max. length of a filename is 255 characters. |
SQLUINTEGER * | fileOptions | Input(Pending) | A pointer to the buffer that holds a file option or an array of file options. Upon SQLExecute() or SQLExecDirect(), there should a file option stored in this buffer.The following option is available: SQL_FILE_READ. |
SQLLEN | fileNameBufferSize | Input | The length of the filename buffer. |
SQLLEN * | Ind | Input(Pending ) | A pointer to the buffer that holds an indicator variable or an array of indicator variables. It cannot be NULL.It is used to determine if LOB is NULL.The following values can be set for the buffer pointed by this pointer: 0, SQL_NULL_DATA. |
Result Values#
SQL_SUCCESS
SQL_SUCCESS_WITH_INFO
SQL_INVALID_HANDLE
SQL_ERROR
Description#
SQLBindFileToParam() binds a LOB parameter marker to a file. SQLBindParameter() can be used to bind a parameter marker to an application variable (memory buffer). For SQLBindFileToParam() and SQLBindParameter(), only the binding by the most recently called bind function is valid.
Because the values of fileName, fileNameLength, fileOptions and ind arguments are referred to upon SQLExecute() or SQLExecDirect(), they should be set before SQLExecute() or SQLExecDirect() is called. When SQLExecute() or SQLExecDirect() is called, data is transferred from the file being bound to DBMS.
If LOB is NULL, the buffer pointed by the ind pointer should be set to SQL_NULL_DATA, and then SQLExecute() or SQLExecDirect() should be called. If LOB is not NULL, the buffer pointed by the ind pointer should be set to 0. The ind argument cannot be a NULL pointer.
To bind an array of files to a parameter marker, all of the fileName, fileNameLength, fileOptions and ind arguments should be arrays.
Diagnosis#
SQLSTATE | Description | Comments |
---|---|---|
08S01 | Communication link fault (Data transmission failure) | Communication link failed before function processing is complete between Altibase CLI driver and DB |
HY000 | General error |
Related Functions#
SQLBindCol
SQLBindFileToCol
SQLExecute
SQLExecDirect
SQLDescribeParam
Examples#
It is assumed that a table has been created with the following DDL.
CREATE TABLE T1 (i1 INTEGER PRIMARY KEY, i2 BLOB);
Input one LOB to a table#
SQLCHAR fileName[16];
SQLLEN fileNameLength = 15;
SQLUINTEGER fileOptions = SQL_FILE_READ;
SQLLEN ind = 0;
.
strcpy(query, "INSERT INTO T1 VALUES (1, ?)");
/* Prepare a statement and bind a file */
if (SQLPrepare(stmt, query, SQL_NTS) != SQL_SUCCESS)
{
execute_err(dbc, stmt, "SQLPrepare : ");
SQLFreeStmt(stmt, SQL_DROP);
return SQL_ERROR;
}
strcpy(fileName, "Terminator2.avi");
if (SQLBindFileToParam(stmt, 1, SQL_BLOB, fileName, &fileNameLength, &fileOptions, 16, &ind) != SQL_SUCCESS)
{
execute_err(dbc, stmt, "SQLBindFileToParam : ");
SQLFreeStmt(stmt, SQL_DROP);
return SQL_ERROR;
}
if (SQLExecute(stmt) != SQL_SUCCESS)
{
execute_err(dbc, stmt, "SQLExecute : ");
SQLFreeStmt(stmt, SQL_DROP);
return SQL_ERROR;
}
Input three LOB's to a table#
SQLINTEGER i1[3];
SQLCHAR fileName[3][10];
SQLLEN fileNameLength[3];
SQLUINTEGER fileOptions[3];
SQLLEN ind[3];
.
if (SQLSetStmtAttr(stmt, SQL_ATTR_PARAMSET_SIZE, (SQLPOINTER) 3, 0) != SQL_SUCCESS)
{
execute_err(dbc, stmt, "SQLSetStmtAttr : ");
SQLFreeStmt(stmt, SQL_DROP);
return SQL_ERROR;
}
if (SQLSetStmtAttr(stmt, SQL_ATTR_PARAM_BIND_TYPE, SQL_PARAM_BIND_BY_COLUMN, 0) != SQL_SUCCESS)
{
execute_err(dbc, stmt, "SQLSetStmtAttr : ");
SQLFreeStmt(stmt, SQL_DROP);
return SQL_ERROR;
}
strcpy(query, "INSERT INTO T1 VALUES (?, ?)");
/* Prepare a statement and bind a file. */
if (SQLPrepare(stmt, query, SQL_NTS) != SQL_SUCCESS)
{
execute_err(dbc, stmt, "SQLPrepare : ");
SQLFreeStmt(stmt, SQL_DROP);
return SQL_ERROR;
}
if (SQLBindParameter(stmt, 1, SQL_PARAM_INPUT, SQL_C_INTEGER, SQL_INTEGER, 0, 0, (SQLPOINTER) i1, 0, NULL) != SQL_SUCCESS)
{
execute_err(dbc, stmt, "SQLBindParameter : ");
SQLFreeStmt(stmt, SQL_DROP);
return SQL_ERROR;
}
if (SQLBindFileToParam(stmt, 2, SQL_BLOB, (SQLCHAR *) fileName, fileNameLength, fileOptions, 10, ind) != SQL_SUCCESS)
{
execute_err(dbc, stmt, "SQLBindFileToParam : ");
SQLFreeStmt(stmt, SQL_DROP);
return SQL_ERROR;
}
/* Specify a file to insert data. */
strcpy(fileName[0], "Cube.avi");
strcpy(fileName[1], "Movie.avi");
strcpy(fileName[2], "Term.avi");
for (i = 0; i < 3; i++)
{
i1[i] = i + 1;
fileNameLength[i] = strlen(fileName[i]);
fileOptions[i] = SQL_FILE_READ;
ind[i] = 0;
}
if (SQLExecute(stmt) != SQL_SUCCESS)
{
execute_err(dbc, stmt, "SQLExecute : ");
SQLFreeStmt(stmt, SQL_DROP);
return SQL_ERROR;
}
Update one LOB in a table#
SQLCHAR fileName[16];
SQLLEN fileNameLength = 15;
SQLUINTEGER fileOptions = SQL_FILE_READ;
SQLLEN ind = 0;
.
strcpy(query, "UPDATE T1 SET i2=? WHERE i1=1");
/* Prepare a statement and bind a file. */
if (SQLPrepare(stmt, query, SQL_NTS) != SQL_SUCCESS)
{
execute_err(dbc, stmt, "SQLPrepare : ");
SQLFreeStmt(stmt, SQL_DROP);
return SQL_ERROR;
}
strcpy(fileName, "Terminator2_fix.avi");
if (SQLBindFileToParam(stmt, 1, SQL_BLOB, fileName, &fileNameLength, &fileOptions, 16, &ind) != SQL_SUCCESS)
{
execute_err(dbc, stmt, "SQLBindFileToParam : ");
SQLFreeStmt(stmt, SQL_DROP);
return SQL_ERROR;
}
if (SQLExecute(stmt) != SQL_SUCCESS)
{
execute_err(dbc, stmt, "SQLExecute : ");
SQLFreeStmt(stmt, SQL_DROP);
return SQL_ERROR;
}