Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Bug reports ➜ DatebaseStep bug?

DatebaseStep bug?

It is now over 60 days since the last post. This thread is closed.     Refresh page


Pages: 1  2 3  

Posted by Ron   China  (15 posts)  Bio
Date Reply #15 on Tue 15 Dec 2009 06:48 PM (UTC)
Message
Hi Nick,

Thanks for your reply.

The problem happened too when i used your Lua code.

I think the problem happened between two different local language system, I know this is very hard to reappear in your computer.

So ignore it please, I have found another way to solve this problem.

Thanks for your help.

Yours,
Ron
Top

Posted by Ddid   China  (19 posts)  Bio
Date Reply #16 on Sat 30 Oct 2010 10:02 PM (UTC)
Message
The same problem has been taken place in mine here.

Just want to know your solution.
Top

Posted by Ddid   China  (19 posts)  Bio
Date Reply #17 on Sat 30 Oct 2010 10:59 PM (UTC)
Message
I am not a C++ expert, but I think maybe following codes is the reason of causing this problem:

SetUpVariantString (vaResult, strResult); 

in methods_database.cpp line 312

and


return strResult.AllocSysString();

in methods_database.cpp line 282
Top

Posted by Nick Gammon   Australia  (23,169 posts)  Bio   Forum Administrator
Date Reply #18 on Sat 30 Oct 2010 11:10 PM (UTC)
Message
Are you using Perl like the original poster?

Can you give me a snippet which reproduces the problem? On page one, I made a test which could not reproduce it.

I am assuming we are dealing in UTF-8, which should be handled OK by SetUpVariantString, however if you can give me some test data I can investigate further.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,169 posts)  Bio   Forum Administrator
Date Reply #19 on Sat 30 Oct 2010 11:16 PM (UTC)
Message
This was my test (in Lua) modified to show the SQL length:


DatabaseOpen ("db", GetInfo (66) .. "utf8_test.db", 6)

DatabaseExec ("db", [[
DROP TABLE IF EXISTS test;
CREATE TABLE test(name TEXT NOT NULL);
]])
      
hello = utils.fromhex ("E5A4A7E5AEB6E5A5BD")  -- utf8: 大家好

print ("length before add=", #hello)

-- insert a record
DatabasePrepare ("db", "INSERT INTO test (name) VALUES ('" .. hello .. "')") 
DatabaseStep ("db") 
DatabaseFinalize ("db")  
      
-- prepare a query
DatabasePrepare ("db", "SELECT name, length(name) from test")

-- execute to get the first row
rc = DatabaseStep ("db")  -- read first row

-- now loop, displaying each row, and getting the next one
while rc == 100 do
  
  values = DatabaseColumnValues ("db")

  print ("length after add=", #values [1])
  print ("name=", utils.tohex (values [1]))
  print ("length from SQL=", values [2])

  rc = DatabaseStep ("db")  -- read next row

end -- while loop

-- finished with the statement
DatabaseFinalize ("db")


DatabaseClose ("db")  -- close it


Output was:


length before add= 9
length after add= 9
name= E5A4A7E5AEB6E5A5BD
length from SQL= 3


Note that the SQL length(name) function correctly reports 3 characters (that is, 3 Unicode characters) rather than 9 bytes.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Ddid   China  (19 posts)  Bio
Date Reply #20 on Sat 30 Oct 2010 11:18 PM (UTC)
Message
I used the same lua testing code, but get different result:

length before add= 9
length after add= 8
name= E5A4A7E5AEB6E5A5


Top

Posted by Nick Gammon   Australia  (23,169 posts)  Bio   Forum Administrator
Date Reply #21 on Sat 30 Oct 2010 11:31 PM (UTC)
Message
Which version of MUSHclient?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Ddid   China  (19 posts)  Bio
Date Reply #22 on Sat 30 Oct 2010 11:38 PM (UTC)
Message
Quote:

Welcome to MUSHclient version 4.61!
Top

Posted by Ddid   China  (19 posts)  Bio
Date Reply #23 on Sat 30 Oct 2010 11:40 PM (UTC)
Message
Nick Gammon said:

This was my test (in Lua) modified to show the SQL length:


DatabaseOpen ("db", GetInfo (66) .. "utf8_test.db", 6)

DatabaseExec ("db", [[
DROP TABLE IF EXISTS test;
CREATE TABLE test(name TEXT NOT NULL);
]])
      
hello = utils.fromhex ("E5A4A7E5AEB6E5A5BD")  -- utf8: 大家好

print ("length before add=", #hello)

-- insert a record
DatabasePrepare ("db", "INSERT INTO test (name) VALUES ('" .. hello .. "')") 
DatabaseStep ("db") 
DatabaseFinalize ("db")  
      
-- prepare a query
DatabasePrepare ("db", "SELECT name, length(name) from test")

-- execute to get the first row
rc = DatabaseStep ("db")  -- read first row

-- now loop, displaying each row, and getting the next one
while rc == 100 do
  
  values = DatabaseColumnValues ("db")

  print ("length after add=", #values [1])
  print ("name=", utils.tohex (values [1]))
  print ("length from SQL=", values [2])

  rc = DatabaseStep ("db")  -- read next row

end -- while loop

-- finished with the statement
DatabaseFinalize ("db")


DatabaseClose ("db")  -- close it


Output was:


length before add= 9
length after add= 9
name= E5A4A7E5AEB6E5A5BD
length from SQL= 3


Note that the SQL length(name) function correctly reports 3 characters (that is, 3 Unicode characters) rather than 9 bytes.


I have run above lua testing code, but got following result:

length before add= 9
length after add= 8
name= E5A4A7E5AEB6E5A5
length from SQL= 3


In fact, I think following code caused this problem:

strResult.AllocSysString();

But, C++, I just know a little bit.
Top

Posted by Nick Gammon   Australia  (23,169 posts)  Bio   Forum Administrator
Date Reply #24 on Sat 30 Oct 2010 11:47 PM (UTC)
Message
DatabaseColumnValues does not call AllocSysString.

DatabaseColumnValues is the call that gets back the data which you are receiving incorrectly.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,169 posts)  Bio   Forum Administrator
Date Reply #25 on Sun 31 Oct 2010 12:17 AM (UTC)
Message
Can you install sqlite3.exe and then open your database, and type:


PRAGMA encoding; 


And tell me what it says?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Ddid   China  (19 posts)  Bio
Date Reply #26 on Sun 31 Oct 2010 12:29 AM (UTC)
Message
Quote:

CString is based on the TCHAR data type. If the symbol _UNICODE is defined for a build of your program, TCHAR is defined as type wchar_t, a 16-bit character encoding type; otherwise, it is defined as char, the normal 8-bit character encoding. Under Unicode, then, CStrings are composed of 16-bit characters. Without Unicode, they are composed of characters of type char.

Above message is copied from:
http://msdn.microsoft.com/en-us/library/ey142t48(v=VS.80).aspx

I think I'm wrong before.

But please check this problem again, above quote message is the reference that about this problem's causing(what I can find):


CString strResult;


Thanks.
Top

Posted by Nick Gammon   Australia  (23,169 posts)  Bio   Forum Administrator
Date Reply #27 on Sun 31 Oct 2010 12:36 AM (UTC)
Message
I have reproduced your problem by changing the "Language for non-Unicode programs" to "Chinese (PRC)".

So at least now I can work out what is causing it...

I think you are probably right, it is something to do with CString.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Ddid   China  (19 posts)  Bio
Date Reply #28 on Sun 31 Oct 2010 12:39 AM (UTC)
Message
Nick Gammon said:

Can you install sqlite3.exe and then open your database, and type:


PRAGMA encoding; 


And tell me what it says?



The result is:

UTF-8
Top

Posted by Ddid   China  (19 posts)  Bio
Date Reply #29 on Sun 31 Oct 2010 12:45 AM (UTC)
Message
Nick Gammon said:

I have reproduced your problem by changing the "Language for non-Unicode programs" to "Chinese (PRC)".

So at least now I can work out what is causing it...

I think you are probably right, it is something to do with CString.


Great!
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


119,160 views.

This is page 2, subject is 3 pages long:  [Previous page]  1  2 3  [Next page]

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.