News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Does assembler pad a buffer?

Started by georgek01, September 01, 2005, 03:58:21 PM

Previous topic - Next topic

georgek01

OK, I've been trying a few things and I'm getting nowhere...

I have a variable szUser db 12 dup (?)

I fill the buffer with data (user name) using GetDlgItemText. Then using SQLBindParameter, I finally pass an SQL statement to a database. If the user enters data of length 12, all works fine. If the user enters anything less than 12, no data is returned. BUT, If I pad the data with spaces in the edit box (to length 12), it works fine.

My question. Does assembler pad the buffer?
What we have to learn to do, we learn by doing.

- ARISTOTLE (384-322 BC)

PBrennick

georgek01,

Move the buffer from .data? to .data and write it like this:
    szUser db 12 dup (20h)

The buffer as you wrote it will be zero filled and evidently this is not desired.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

georgek01

Does the same thing...  :(

If I pad the data with the required amount of spaces, it works.
What we have to learn to do, we learn by doing.

- ARISTOTLE (384-322 BC)

georgek01

PBrennick,

It appears using szUser db 12 dup (20h) also causes unwanted buffering.

I've even tried trimming (StrTrim) the string before passing it on to the API. Still does the same as before.

Is it possible to dynamically resize the buffer - if so, I could resize the buffer according to the size of the string...?
What we have to learn to do, we learn by doing.

- ARISTOTLE (384-322 BC)

PBrennick

I think you need to explain what unwanted buffering is.  If you start with a buffer of 12 spaces and store 6 characters into it you wind up with a buffer that has 6 characters and is padded to 12 with spaces which is exactly the same as what you originally said you had to do to get it to work.  All I did was simplify it for you and if it worked before it should work now, also, so your comment makes absolutely no sense to me.

If you still have to pad it out with spaces, either you are not explaining this sufficiently or there is a problem elsewhere in your code.

Are you willing to attach the project?

Paul
The GeneSys Project is available from:
The Repository or My crappy website

Tedd

What are the parameters that you're passing to SQLBindParameter (meanings and values) ??


"szUser db 12 dup (?)" will create an 'array' with space for exactly 12 characters. The actual contents of that array are not specified or promised, but for now we can assume they are all zero. So szUser = [------------]  (I'm just using - for zero here.)
When you do GetDlgItemText, the contents of the dialog box are copied into the supplied buffer, and ended with a zero (otherwsie how would you know where the end is?) So now szUser = [mr tedd-----]
Note at this point that there are still exactly 12 characters in the array, but only the first 7 have letters (you know it's 7 because the 8th is a zero.)
If you then pad the whole thing with spaces, you will get [mr tedd     ]  which has no zero to indicate the end of the string (but you know it's 12 characters anyway.)

I'm taking a guess here, but I'm assuming the sql function requires you to specify how long the string is, and you're saying 12 each time. When the szUser is 'full' of characters, this works because there really are 12 characters. But when there are less than 12, is fails because you're saying there are 12, but really there are (say) 7 and some extra zeroes.
GetDlgItemText does return the number of (real) characters copied into the buffer, so knowing this is no problem. Maybe you should be telling sql to bind the parameter whose length is the value returned by GetDlgItemText, and not simply 12 every time??
No snowflake in an avalanche feels responsible.

PBrennick

Tedd,
That sounds right to me and is pretty much what I suspected.  That is why I wanted to see the source because I know nothing about SQLBindParameter so I needed to see how it is being used.  Thanks for helping.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

MichaelW

Perhaps the SQLSTATE value (returned by SQLGetDiagRec) might provide some useful information.

MSDN: SQLBindParameter

eschew obfuscation

PBrennick

Michael,
Thanks for the heads up, it looks like he needs to set the bufferlength parameter in the structure 'on the fly' as a result of what is input.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

georgek01

I really feel stupid. This is a classic case of jumping into something before reading the manual  :red

SQLBindParameter requires the following parameters:

   
   StatementHandle:DWORD,
   InputOutputType:DWORD,
   ValueType:DWORD,
   ParameterType:DWORD,
   ColumnSize:DWORD,
   DecimalDigits:DWORD,
   ParameterValuePtr:DWORD,
   BufferLength:DWORD,
   pStrLenOrIndPtr:DWORD


I was filling the last parameter with SIZEOF szUser - and this is quite legal, OR I can pass (amongst others) SQL_NTS [string is null-terminated]. Once I passed in the latter, all works fine.

Thank you all for your assistance!!
What we have to learn to do, we learn by doing.

- ARISTOTLE (384-322 BC)

Tedd

No snowflake in an avalanche feels responsible.