Why not use the length of the string. In your above example, try 2047 instead of 256. Now, since you figured it out, decrease the length of query to save memory
I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).