ODBC Bulk insert char * strings added trailing white space

Answered ODBC Bulk insert char * strings added trailing white space

  • Sunday, September 02, 2012 1:13 AM
     
     

    Hi,

    This question is related to Bulk insert without trailing space.

    I have the same issue on this call:

        SQLRETURN rc = SQLBindParameter(hstmt_, 1,
                                        SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, size, 0,
                                        static_cast<SQLPOINTER>(data), size, inds);

    Changing SQL_CHAR to SQL_VARCHAR didn't resolve the issue.  How can I bulk insert an array of char* strings without trailing white spaces?  Unfortunately SQL_WVARCHAR is not an option as we need to be able to handle char* strings.

    Thanks.

All Replies

  • Tuesday, September 04, 2012 1:35 AM
    Moderator
     
     

    Hi xinonnet,

    Thank you for your question.  

    I am trying to involve someone more familiar with this topic for a further look at this issue. Sometime delay might be expected from the job transferring. Your patience is greatly appreciated.  

    Thank you for your understanding and support


    Best Regards,
    Iric
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

  • Wednesday, September 05, 2012 9:45 PM
    Moderator
     
     

    Hello,

    With my poor english, i am not sure that i have understood your question in the correct way. Do you want to eliminate all the white spaces at the end of your array of char * ?  Maybe a little like the String.TrimEnd() of .Net Framework

    http://msdn.microsoft.com/en-us/library/system.string.trim(VS.90).aspx

    Please, could you post the code with the BulkInsert ? I have written in VC++ ( 4 => 6 ) upto 2003 when VC# arrived but i am returning towards VC++ . A little return towards the old time of C++ Borland or Microsoft will be a pleasure for me. It is why i will have a look at this problem

    I don't think that BulkInsert is offering this possibility.

    Please, also , could you explain why you want to "trim" the white spaces at the end of your char * ? To avoid to write too many useless characters at the end   ? I think it is a question more related to VC++ than related to SQL Server Data Access. If it is the case, a moderator can move your thread towards a VC++ forum , this will avoid to have to recreate a thread, to loose post or to let this thread dying.

    Have a nice day


    Mark Post as helpful if it provides any help.Otherwise,leave it as it is.

  • Thursday, September 06, 2012 6:46 PM
     
     

    Hi, Papy,

    SQL Server appended white characters to my strings when I called SQLBindParameter on an array of parameters.  It is a SQL Server problem since when I used the same ODBC interface to connect to a MYSQL server, the problem disappeared.

    Thanks.

  • Thursday, September 06, 2012 10:43 PM
    Moderator
     
     Answered

    Hello,

    Please, could you provide more informations about your SQL Server instance, that's to say the full version ( year + last installed service pack ) and edition ( Express but which one : basic, with Advanced Services,... or Web, Workgroup , Standard  , Entreprise , ... ) ?

    Please, could you also tell us what is the value of the AnsiPaddingEnabled facet ?

    To obtain this value, you can use SQL Server Management Studio to connect to your SQL Server instance :

    in the left panel , double-click on the name of the SQL Server instance to expand the nodes

    double-click on the databases node to expand it 

    select the name of your database , right-click on the name of the database and in the conceptual menu , click on the Facets menuitem

    You will arrive in a new form labelled something like Facets display - DatabaseName ( for me AdventureWorks )

    Check that the selected facet is Database . You will find AnsiPaddingEnabled as the 4rd row from the beginning of the datagrid  

    For more explanations about this property , see ( for example ) :

    http://msdn.microsoft.com/en-us/library/ms186823(SQL.100).aspx

    you can also use the DATABASEPROPERTYEX function to get this value if you are not fond of facets ( i am often using SMO to manage SQL Server instances or databases and the facets are the simplest way to get informations on the SQL Server objects )

    Please, also, could you provide the definition of the corresponding column in your table ? ( i think that if you have a CHAR(XX) or a NCHAR(XX) definition for this column, SQL Server fills the column with the string provided in your SQLBindParameter and adds enough spaces to reach the XX size )

    We are waiting for your feedback to try to help you more effitiently

    Have a nice day


    Mark Post as helpful if it provides any help.Otherwise,leave it as it is.