newlisp to get mysql table command lead to messy code

Pondering the philosophy behind the language

newlisp to get mysql table command lead to messy code

Postby shanquan2006 » Fri Jul 04, 2014 5:30 am

I study newLisp for two weeks. Now I was trying to connect mysql to get "create table sql", but it cause messy code .

the code is :
Code: Select all
 
 (:connect db mysql-host mysql-user mysql-pwd mysql-db mysql-port)
 (set 'r (:query db (append "show create table " mysql-table-name))) 
 (set 'mysql_sql ((((:fetch-all r) 0) 1) 1))   
 (println mysql_sql )

the result is :
Code: Select all
CREATE TABLE `tvsn` (
                `order_id` varchar(13) NOT NULL COMMENT '??ID',
                `sn` varchar(50) NOT NULL COMMENT '??SN?'
               ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='???????SN?'

but in mysqlclient, the result is :

Code: Select all
CREATE TABLE `tvsn` (
  `order_id` varchar(13) NOT NULL COMMENT '订单ID',
  `sn` varchar(50) NOT NULL COMMENT '电视SN码'
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='电视机SN码'       


some description of mysql.lsp is:
;; @module Mysql
;; @author Jeff Ober <jeffober@gmail.com>, Kanen Flowers <kanendosei@gmail.com>
;; @version 1.05 beta
;; @location http://static.artfulcode.net/newlisp/mysql.lsp
;; @package http://static.artfulcode.net/newlisp/mysql.qwerty
;; @description A new MySQL module to replace the distribution standard module (requires newlisp 10).

how to solve it ?
shanquan2006
 
Posts: 3
Joined: Fri Jul 04, 2014 4:41 am

Re: newlisp to get mysql table command lead to messy code

Postby hotcore » Sat Jul 05, 2014 3:24 pm

Maybe you don't have installed the UTF-8 version? http://www.newlisp.org/index.cgi?page=Downloads
hotcore
 
Posts: 29
Joined: Fri Aug 26, 2011 1:03 pm

Re: newlisp to get mysql table command lead to messy code

Postby shanquan2006 » Sun Jul 06, 2014 2:32 am

hotcore wrote:Maybe you don't have installed the UTF-8 version? http://www.newlisp.org/index.cgi?page=Downloads


The version I installed is:

Code: Select all
-OptiPlex-3020:~$ newlisp --version
newLISP v.10.6.0 64-bit on Linux IPv4/6 UTF-8 libffi, options: newlisp -h
shanquan2006
 
Posts: 3
Joined: Fri Jul 04, 2014 4:41 am

Re: newlisp to get mysql table command lead to messy code

Postby ralph.ronnquist » Sun Jul 06, 2014 6:09 am

A quick glance into the source indicates that "println" is not very i18n friendly, though I don't have too much experience with it myself. Thus, my theory is that the string in newlisp is correct (i.e., the same as the other), but presented badly by println. Maybe a raw string output works better?
Code: Select all
(write 1 <text>)
ralph.ronnquist
 
Posts: 179
Joined: Mon Jun 02, 2014 1:40 am
Location: Melbourne, Australia

Re: newlisp to get mysql table command lead to messy code

Postby shanquan2006 » Sun Jul 06, 2014 9:17 am

ralph.ronnquist wrote:A quick glance into the source indicates that "println" is not very i18n friendly, though I don't have too much experience with it myself. Thus, my theory is that the string in newlisp is correct (i.e., the same as the other), but presented badly by println. Maybe a raw string output works better?
Code: Select all
(write 1 <text>)


I modefied the program with your mehod, but the question is sitll not to solve.
Code: Select all
 (write 1 ((((:fetch-all r) 0) 1) 1)) 


and I checked mysql code is
Code: Select all
mysql> show variables like 'character%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
shanquan2006
 
Posts: 3
Joined: Fri Jul 04, 2014 4:41 am

Re: newlisp to get mysql table command lead to messy code

Postby ralph.ronnquist » Sun Jul 06, 2014 3:41 pm

Maybe you can explain the problem a bit more in detail.

I understood it to be that the strings in the COMMENT phrases look different in the newlisp printing than in your 'mysqlclient', which by extension might lead us to assume that the string values are different.

My theory was that the string values are actually the same in the programs, but they get presented differently; maybe it is that the console shows unicode characters, and mysqlclient has a utf8-to-unicode filter, whilst newlisp doesn't. How about saving the newlisp output to a file, and then you view this with your utf8 aware text editor?

Or maybe I don't know at all what I'm taking about and should sit quiet for a while.
ralph.ronnquist
 
Posts: 179
Joined: Mon Jun 02, 2014 1:40 am
Location: Melbourne, Australia

Re: newlisp to get mysql table command lead to messy code

Postby csfreebird » Tue Jul 29, 2014 3:05 am

I fixed this problem. Just execute the following commands in newlisp before querying data from mysql table.

Code: Select all
(MySQL:query "SET character_set_client = utf8;")
true

(MySQL:query "SET character_set_connection = utf8;")
true
 (MySQL:query "SET character_set_results = utf8;")


Then check it:
Code: Select all
> (MySQL:query "SHOW VARIABLES LIKE 'character%';")
true
> (dotimes (x (MySQL:num-rows)) (println (MySQL:fetch-row)))
("character_set_client" "utf8")
("character_set_connection" "utf8")
("character_set_database" "utf8")
("character_set_filesystem" "binary")
("character_set_results" "utf8")
("character_set_server" "utf8")
("character_set_system" "utf8")
("character_sets_dir" "/usr/share/mysql/charsets/")
("character_sets_dir" "/usr/share/mysql/charsets/")
csfreebird
 
Posts: 107
Joined: Tue Jan 15, 2013 11:54 am
Location: China, Beijing

Re: newlisp to get mysql table command lead to messy code

Postby Lutz » Tue Jul 29, 2014 4:37 pm

This is now part of the documentation: http://www.newlisp.org/code/modules/mysql.lsp.html for the standard module.
Lutz
 
Posts: 5259
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California


Return to Whither newLISP?

Who is online

Users browsing this forum: No registered users and 1 guest

cron