Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mssql.d :How to Insert a wstring? And sqlException not work #62

Closed
FrankLIKE opened this issue Jan 15, 2015 · 5 comments
Closed

mssql.d :How to Insert a wstring? And sqlException not work #62

FrankLIKE opened this issue Jan 15, 2015 · 5 comments

Comments

@FrankLIKE
Copy link

db.query("INSERT INTO mytableVALUES('namevalue')");
if the namevalue comes from wstring.I get string by toMBS fuction, but it not work,and not get the sqlException.
Thank you.

@adamdruppe
Copy link
Owner

On Thu, Jan 15, 2015 at 07:36:03AM -0800, FrankLIKE wrote:

if the namevalue comes from wstring.I get string by toMBS fuction, but it not work,and not get the sqlException.

I would say just convert it to a string with

import std.conv;

to!string(your_wstring);

That's not the most efficient but I'm pretty sure it would work.

@FrankLIKE
Copy link
Author

Thank you.

@FrankLIKE
Copy link
Author

toMBS function work ok,it can let the wstring in mssql db display ok.
to!string(wstring) can dispaly ok on gui,but not ok in mssql db.
Two words wstring is ok,but three words wstring is not ok.why?
Thank you.

@adamdruppe
Copy link
Owner

On Thu, Mar 26, 2015 at 09:32:52AM -0700, Zafer �elenk wrote:

Why "get data" gives the error? Can you help?

It might be returning SQL_SUCCESS_WITH_DATA, my check there i think is
too broad.

Try changing line 159 to something like plain

SQLGetData(statement, cast(ushort)(i+1), SQL_CHAR, buf.ptr, 255, &ptr);
//if(SQLGetData(statement, cast(ushort)(i+1), SQL_CHAR, buf.ptr, 255, &ptr) != SQL_SUCCESS) 
//throw new DatabaseException("get data: " ~ getSQLError(SQL_HANDLE_STMT, statement)); 

So removing the error checking. Then see if it works. If it does, we
should be able to make it

auto returned = SQLGetData(statement, cast(ushort)(i+1), SQL_CHAR, buf.ptr, 255, &ptr);
if(returned != SQL_SUCCESS && returned != SQL_SUCCESS_WITH_INFO)
    throw new DatabaseException("get data: " ~ getSQLError(SQL_HANDLE_STMT, statement)); 

And hopefully that will work. I don't have a MS SQL server up right
now so can't test it myself but this is my hunch.

@zafer06
Copy link

zafer06 commented Mar 27, 2015

SQLGetData(statement, cast(ushort)(i+1), SQL_CHAR, buf.ptr, 255, &ptr); 
--if(SQLGetData(statement, cast(ushort)(i+1), SQL_CHAR, buf.ptr, 255, &ptr) != SQL_SUCCESS) 
--throw new DatabaseException("get data: " ~ getSQLError(SQL_HANDLE_STMT, statement));

Yes it works this way. But just bought the first 83 rows of the table?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants