Bug #3068 [Prompt without seconds when set from INI file]
Submitted: 4 Mar 2004 16:41 Modified: 8 Mar 2004 13:53
Reporter: Paul Dubois Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S3 (Non-critical)
Version:4.0.19 OS:
Assigned to: Paul Dubois CPU Architecture:Any

[4 Mar 2004 16:41] Paul Dubois
Description:
I get the same result as reported by the user below.
I'll just paste in the original mail message.

---------
Mailing-List: contact win32-help@lists.mysql.com; run by ezmlm
Delivered-To: mailing list win32@lists.mysql.com
From: "Marcelo B." <marcelobe2003@yahoo.com.ar>
To: <win32@lists.mysql.com>
Subject: [Prompt without seconds when set from INI file]
Date: Thu, 4 Mar 2004 00:14:46 -0000

Description:
 <Using this statement from my.ini file doesn't work as it does when typed at the command line:
         [mysql]
         prompt="mysql \R:\m:\s> "
         failing in state the field -seconds- they become just one white space. I even tried to put seconds 
in-place of minutes and viceversa: seconds still missing.>

How-To-Repeat:
 <include into your my.ini file, the following:
         [mysql]
         prompt="mysql \R:\m:\s> "
         the next mysql window you open will give you the prompt with blank seconds. When you type this 
prompt command at the mysql command line, it does work properly.
There is something really weird with the prompt command. This is a log file I got experimenting with it:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 29 to server version: 4.0.18-nt

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql 23:56: > prompt="mysql \R:\m:\s> "
    -> ;
ERROR 1064: You have an error in your SQL syntax.  Check the manual that corresp
onds to your MySQL server version for the right syntax to use near 'prompt="mysq
l \R:\m:\s> "' at line 1
mysql 0:04: > prompt "mysql \R:\m:\s> ";
PROMPT set to '"mysql \R:\m:\s> "'
"mysql 0:04:14> "prompt mysql \R:\m:\s> ;
PROMPT set to ';'
    -> prompt mysql \R:\m:\s> ;
PROMPT set to ';'
    -> prompt 'mysql \R:\m:\s> ';
PROMPT set to 'mysql
prompt mysql
prompt 'mysql \R:\m:\s> ''
mysql
prompt mysql
prompt 'mysql 0:05:1> 'prompt (mysql \R:\m:\s> );
PROMPT set to ');'
    -> prompt mysql \R:\m:\s>
Returning to default PROMPT of mysql>
    -> prompt
    -> prompt mysql\R:\m:\s>
Returning to default PROMPT of mysql>
    -> prompt \R:\m:\s>
Returning to default PROMPT of mysql>
    -> prompt "mysql \R:\m:\s> ";
PROMPT set to '(mysql
prompt mysql
prompt
prompt mysql
prompt
prompt "mysql \R:\m:\s> "'
(mysql
prompt mysql
prompt
prompt mysql
prompt
prompt "mysql 0:06:8> "prompt "mysql \R:\m:\s> ";
PROMPT set to '"mysql \R:\m:\s> "'
"mysql 0:06:25> "
"mysql 0:06:38> "prompt "mysql \R:\m:\s> ";
PROMPT set to '"mysql \R:\m:\s> "'
"mysql 0:06:49> "prompt "mysql \R:\m:\s> ";
PROMPT set to '"mysql \R:\m:\s> "'
"mysql 0:06:50> "prompt "mysql \R:\m:\s> ";
PROMPT set to '"mysql \R:\m:\s> "'
"mysql 0:06:51> "prompt mysql \R:\m:\s>\_;
Returning to default PROMPT of mysql>
    -> prompt mysql \R:\m:\s>\_
Returning to default PROMPT of mysql>
    -> prompt mysql>\_
ERROR:
Unknown command '\_'.
    -> prompt mysql>
    -> prompt
    -> prompt mysql
    -> prompt "mysql \R:\m:\s> ";
PROMPT set to 'mysql
prompt mysql
prompt mysql>\_
prompt mysql>
prompt
prompt mysql
prompt "mysql \R:\m:\s> "'
mysql
prompt mysql
prompt mysql>
prompt mysql>
prompt
prompt mysql
prompt "mysql 0:09:20> "prompt mysql \R:\m:\s>\_
PROMPT set to 'mysql \R:\m:\s>\_'
mysql 0:09:28>
>

Fix:
 <dunno>

Synopsis: <seconds missing>
Submitter-Id: <Marcelo B.>
Originator: <Marcelo>
Organization:   <Disorganized>
MySQL support:  [none]
Severity: [non-critical]
Priority: [low]
Category: [mysql client]
Class:  [sw-bug]
Release: mysql-4.0.18nt

Exectutable:   [mysql.exe]
Environment:   <compaq LA 1711>
System:        <Win2000-Pro>
Compiler:      
Architecture:  i386

How to repeat:
See above.
[4 Mar 2004 17:01] Paul Dubois
Upon further reflection, it would appear that \s turning into
a space is probably a result of \s being interepreted as
an escape sequence -- which is normal for the way that
MySQL interprets strings. You can get seconds by using
\\s in the option file argument.  However, this is still
problematic:
- You don't need an extra backslash before the other
  special prompt sequences (\R, \m).
- If you do add a backslash before \R and \m, they
  still work.

In addition (an unrelated problem), seconds displays
using only one digit when the seconds value is < 10.
[7 Mar 2004 4:21] Sergei Golubchik
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.mysql.com/documentation/ and the instructions on
how to report a bug at http://bugs.mysql.com/how-to-report.php

Additional info:

Though, I agree that is it confusing in this particular case, it is not a bug:

http://www.mysql.com/doc/en/Option_files.html
"
Note that for options and values, all leading and trailing blanks are automatically deleted. You may use the escape sequences `\b', `\t', `\n', `\r', `\\', and `\s' in option values to represent the backspace, tab, newline, carriage return, and space characters.
"

Paul, may be you can clarify it, where mysql prompt variable it documented ?
[7 Mar 2004 12:24] Paul Dubois
Okay, I've added this text to the manual:

Note that if you set the prompt using a @code{--prompt} option in an option
file, it is advisable to double the backslashes when using the special
prompt options. Otherwise, you may run into problems because there is
some overlap in the set of allowable prompt options and the set of special
escape sequences that are recognized in option files. These sequences are
listed in @ref{Option files}.

Still, what about the problem that seconds displays only as a single digit
for seconds values < 10? That looks pretty weird.
[7 Mar 2004 18:41] Paul Dubois
Here is a patch to cause \s in the prompt
to always display with two digits. It actually
causes hours to display with two digits as
well. (That way, times in the prompt have
a constant width.)  I guess it's debatable
whether that should happen for the hours
value, but having seconds display with a
single digit sometimes is just wrong. :-)

This patch actually applies against either
the 4.0 or 4.1 tree.

===== mysql.cc 1.160 vs edited =====
--- 1.160/client/mysql.cc	Wed Mar  3 14:51:00 2004
+++ edited/mysql.cc	Sun Mar  7 20:29:12 2004
@@ -3183,6 +3183,8 @@
 	processed_prompt.append(' ');
 	break;
       case 'R':
+	if (t->tm_hour < 10)
+	  processed_prompt.append('0');
 	add_int_to_prompt(t->tm_hour);
 	break;
       case 'r':
@@ -3190,6 +3192,8 @@
 	getHour = t->tm_hour % 12;
 	if (getHour == 0)
 	  getHour=12;
+	if (getHour < 10)
+	  processed_prompt.append('0');
 	add_int_to_prompt(getHour);
 	break;
       case 'm':
@@ -3215,6 +3219,8 @@
 	processed_prompt.append(strtok(dateTime,"\n"));
 	break;
       case 's':
+	if (t->tm_sec < 10)
+	  processed_prompt.append('0');
 	add_int_to_prompt(t->tm_sec);
 	break;
       case 'w':
[8 Mar 2004 13:32] Sergei Golubchik
Paul, could you please push this patch in 4.0.19 and close the bug ?
[8 Mar 2004 13:53] Paul Dubois
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html