Note that there are some explanatory texts on larger screens.

plurals
  1. POCan ColumnSize argument of ODBC SQLBindParameter be strlen(param) + 1 for SQLCHAR type parameter?
    primarykey
    data
    text
    <p>The example for SQLBindParameter function at <a href="http://msdn.microsoft.com/en-us/library/ms710963(v=vs.85).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms710963(v=vs.85).aspx</a> passes the size of the character array as the ColumnSize argument (6th argument) when the C type is <code>SQL_C_CHAR</code>.</p> <p>Quoting parts of the examples from that page:</p> <pre><code>SQLCHAR szEmployeeID[EMPLOYEE_ID_LEN]; SQL_DATE_STRUCT dsOrderDate; SQLINTEGER cbCustID = 0, cbOrderDate = 0, cbEmployeeID = SQL_NTS; </code></pre> <p>...</p> <pre><code>retcode = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, EMPLOYEE_ID_LEN, 0, szEmployeeID, 0, &amp;cbEmployeeID); </code></pre> <p>I want to know if it is okay to pass the length of the string parameter plus 1 as the ColumnSize argument. In other words, I want to know if the following call is okay if we assume that <code>szEmployeeID</code> contains a null-terminated string.</p> <pre><code>retcode = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(szEmployeeID) + 1, 0, szEmployeeID, 0, &amp;cbEmployeeID); </code></pre> <p>I believe this can be very useful in calls like these:</p> <pre><code>SQLLEN nts = SQL_NTS; retcode = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, 6, 0, "hello", 0, &amp;nts); char *domain = "stackoverflow.com"; retcode = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(domain) + 1, 0, domain, 0, &amp;nts); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload