Bug #23378 When a file is saved garbage is entered in the first line ( ∩╗┐)
Submitted: 17 Oct 2006 15:51 Modified: 20 Dec 2006 14:02
Reporter: marc castrovinci (Basic Quality Contributor) Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Query Browser Severity:S3 (Non-critical)
Version:1.2.4 OS:Windows (XP and Linux (ubuntu))
Assigned to: Mike Lischke CPU Architecture:Any
Tags: , file, garbage, jargon, save

[17 Oct 2006 15:51] marc castrovinci
Description:
When you create a script and save, is inserted in the first line. It doesn't effect anything til you run the script from a command line. The error that results is:

>mysql -u root -ptestpwd < test.sql
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the ma
nual that corresponds to your MySQL server version for the right syntax to use n
ear 'use test' at line 1

This happens in Windows and Linux.

If you go back and save the file as a ANSI type sql file it wont happen.

How to repeat:
CREATE DATABASE test; 

`test`.CREATE DATABASE `test` /*!40100 DEFAULT CHARACTER SET latin1 */;

DROP TABLE IF EXISTS `test`.`t1`;
CREATE TABLE  `test`.`t1` (
  `a` int(11) NOT NULL auto_increment,
  PRIMARY KEY  (`a`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

DROP TABLE IF EXISTS `test`.`t2`;
CREATE TABLE  `test`.`t2` (
  `a` int(11) default NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Now open a new script tab in QB and enter:
use test;

insert into t1 values(1);
insert into t2 values(2);
insert into t1 values(3);

save it.

Goto command line and run the script
>mysql -u root -ptestpwd < test.sql

Should get the error:
>mysql -u root -ptestpwd < test.sql
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the ma
nual that corresponds to your MySQL server version for the right syntax to use n
ear 'use test' at line 1

Now go back in QB and save it as an ANSI .sql

Run again on command line and it works fine.

Suggested fix:
Why not automatically save it as an ANSI .sql
[17 Oct 2006 16:32] MySQL Verification Team
Thank you for the bug report.
[20 Dec 2006 14:02] Mike Lischke
Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://dev.mysql.com/doc/ and the instructions on
how to report a bug at http://bugs.mysql.com/how-to-report.php

As additional info: your suggested fix would only mess things up in the non-latin world. I strongly recommend that you inform yourself about modern encoding techniques, particularly Unicode (www.unicode.org). The extra chars you see in the scripts files comprise a socalled BOM (byte order mark). Read http://en.wikipedia.org/wiki/Byte_Order_Mark for more info.

However, things aren't so bad and there is a solution for you if you insist on the old-fashioned ANSI encoding. When you save your script the first time (or by using "Save As") you can specify the encoding to be used for it in the save dialog. Right the first entry is your preferred ANSI.