converted sqlite db wont import with phpmyadmin - mysql

Converted sqlite3 to mysql, but the import fails in phpMyAdmin and produces this error: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'PRIMARY KEY NOT NULL ,sequence VARCHAR,items_count INTEGER,total FLOAT,`c' at line 1
What am I missing?
DROP TABLE IF EXISTS `orders`;
CREATE TABLE `orders` (`id` VARCHAR PRIMARY KEY NOT NULL ,`sequence` VARCHAR,`items_count` INTEGER,`total` FLOAT,`change` FLOAT,`tax_subtotal` FLOAT,`surcharge_subtotal` FLOAT,`discount_subtotal` FLOAT,`payment_subtotal` FLOAT,`rounding_prices` VARCHAR,`precision_prices` VARCHAR,`rounding_taxes` VARCHAR,`precision_taxes` VARCHAR,`status` INTEGER,`service_clerk` VARCHAR,`service_clerk_displayname` VARCHAR,`proceeds_clerk` VARCHAR,`proceeds_clerk_displayname` VARCHAR,`member` VARCHAR,`member_displayname` VARCHAR,`member_email` VARCHAR,`member_cellphone` VARCHAR,`invoice_type` VARCHAR,`invoice_title` VARCHAR,`invoice_no` VARCHAR,`invoice_count` INTEGER,`destination` VARCHAR,`table_no` INTEGER,`check_no` INTEGER,`no_of_customers` INTEGER,......

There is a litte differnce between SQLite and MySQL syntax.
Below answer is taken from here
Here a list of ALL the differences in SQL syntax that I know about between the two file formats: The lines starting with:
BEGIN TRANSACTION
COMMIT
sqlite_sequence
CREATE UNIQUE INDEX
are not used in MySQL
SQLlite uses CREATE TABLE/INSERT INTO "table_name" and MySQL uses CREATE TABLE/INSERT INTO table_name
MySQL doesn't use quotes inside the schema definition
MySQL uses single quotes for strings inside the INSERT INTO clauses
SQLlite and MySQL have different ways of escaping strings inside INSERT INTO clauses
SQLlite uses 't' and 'f' for booleans, MySQL uses 1 and 0 (a simple regex for this can fail when you have a string like: 'I do, you don\'t' inside your INSERT INTO)
SQLLite uses AUTOINCREMENT, MySQL uses AUTO_INCREMENT
The above link will help more regarding this.

Related

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use problem 12

CREATE TABLE Meta_data(Name_list_id VARCHAR DEFAULT (CONCAT('NL', AUTO_INCREMENT)),Result_id VARCHAR DEFAULT (CONCAT('RS', AUTO_INCREMENT)),No_of_subject int);
enter image description here
in above Name_list_id generate NL01,NL02,NL03....,
and Result_id generate RS01,RS02,RS03...,
can help to correct solution provide this query
for "mysql database"
It will be better if your ID values are numbers, not strings. Your syntax is incorrect - you are not allowed to create AUTO_INCREMENT on strings. Also, you are not able to use AUTO_INCREMENT column in GENERATED columns.
And now you are looking for the following:
NL01,NL02,NL03, ...
but what if we have 99+ records?
If you are using numbers, you will be able to format them when the data is read. For example, using LPAD function:
SELECT CONCAT('NL',LPAD(result_id,5,'0'))
FROM mytable

How to rename table and change storage type in MySQL?

I first create a table which is set to store data in MyISAM engine. Later this table would be replaced with new table, but I still whant to keep this table and just rename it and change her engine type to "archive". I have try this:
ALTER TABLE myTable RENAME TO myTable-[DATE] ENGINE=archive;
Error which I get is: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ENGINE=archive' at line 1 (1064) (SQLExecDirectW)")"
So how to in mysql rename and convert table from MyISAM to ARCHIVE engine?
Tnx for help
Kindly try this:
ALTER TABLE `test1` RENAME TO `myTable-[18-Aug-2015]`, ENGINE=archive;
Pass the new name as a string as well. Make sure to also include a comma ( , ) between the alterations that you require.

Asigning 2 integer values to a single item in a table in MySQL?

I have this line in an SQL table:
Income NUMBER(12,2),
And I want to recreate the table in mysql, but it's throwing me this error:
error 1064 (42000): You have an error in your SQL syntax; check the manual to use near '2))' at line 4
This is how I'm creating the table:
CREATE TABLE Doctors(
DoctorId INTEGER(5) PRIMARY KEY,
DoctorName VARCHAR(20),
Income INTEGER(12,2));
How can I do this in mysql?
*I have been able to replicate the table in sqlite without errors.
If you are trying to do what your question title states (i.e. store two integer values into the same column), you may be looking to use an array. Databases like PostgreSQL support arrays (see PostgreSQL array documentation), but MySQL doesn't do so natively (see MySQL Documentation). However, the MySQL documentation suggests using a language extension to serialise/deserialise the data (see PHP example).
Otherwise, it may be that you are simply looking for a DECIMAL type:
Income DECIMAL(12,2)
See MySQL Documentation for fixed-point types

SQLite to MySQL strange error #1064

I'm converting a SQLite database to MySQL so I can import it to PHPMyAdmin.
This should be straightforward. I exported it to a dump, changed the autoincrements and changed all double quotes to backticks. This is what the start of the resulting file looks like:
DROP TABLE IF EXISTS `chars`;
CREATE TABLE chars(
charid INTEGER PRIMARY KEY AUTO_INCREMENT,
character TEXT
);
INSERT INTO `chars` VALUES(3,'a');
INSERT INTO `chars` VALUES(4,'b');
...
When trying to import to PHPMyAdmin it throws this error.
Error
SQL query:
CREATE TABLE chars(
charid INTEGER PRIMARY KEY AUTO_INCREMENT ,
CHARACTER TEXT
);
MySQL said:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'character TEXT
)' at line 3
Is there too much space after the indented line? I left the "format" option as "SQL", left SQL compatibility mode as NONE and left "Do not use AUTO_INCREMENT for zero values" ticked.
Its going to be used in a django web app.
CHARACTER is a reserved word in mySQL. I'm betting that is the reason.
Use either a different column name (preferred), or use backticks:
`CHARACTER` TEXT

Symfony doctrine::build task cannot create table named order

I have a database with a table named order.
When i run php symfony doctrine:build --all, i got the folowing error:
SQLSTATE[42000]: Syntax error or
access violation: 1064 You have an
error in your SQL syntax; check the
manual that corresponds to your MySQL
server version for the right syntax to
use near 'order (id BIGINT
AUTO_INCREMENT, status VARCHAR(255),
colissimonumber VARCHAR(25' at line 1.
Failing Query: "CREATE TABLE order (id
BIGINT AUTO_INCREMENT, status
VARCHAR(255), colissimonumber
VARCHAR(255) NOT NULL, created_at
DATETIME NOT NULL, updated_at DATETIME
NOT NULL, PRIMARY KEY(id)) ENGINE =
MyISAM".
The problem is clearly that order has no backquotes arount it (if i run manually the query in phpmyadmin with backquotes, it works)
How do i tell doctrine to add backquotes around table and field names? Any workaround exept renaming my table ?
I run symfony 1.4.9 with doctrine 1.2
You can turn on Doctrine_Core::ATTR_QUOTE_IDENTIFIER in your doctrine configuration mthod on projectConfiguration which will quote tables and col names but its not recommended:
Just because you CAN use delimited
identifiers, it doesn't mean you
SHOULD use them. In general, they end
up causing way more problems than they
solve. Anyway, it may be necessary
when you have a reserved word as a
field name (in this case, we suggest
you to change it, if you can).
http://www.doctrine-project.org/projects/orm/1.2/docs/manual/configuration/en#identifier-quoting
You probably want your model to be named Order, but this doesn't mean that the corresponding RDBMS table must be named the same.
Order:
tableName: project_order
columns: ...
Got similar error when upgrading from MySQL 5.7 to MySQL 8.0. RANK() is a function added in MySQL 8.0 whereas one of the table in our database has rank as column name.
My Setup:
- Symfony 1.5
- Doctrine 1.2
- PHP 7.4.24
- MySQL 8.0.27
- Ubuntu 20.04.1
Here are three possible solutions.
Solution 1: Add quote_identifier: true in config/databases.yml file. Also, clear cache after change in configuration with php symfony cc or php symfony cache:clear.
all:
doctrine:
param:
attributes:
quote_identifier: true
Solution 2: Turn on Doctrine_Core::ATTR_QUOTE_IDENTIFIER in config/ProjectConfiguration.class.php file on configureDoctrine() method.
$conn = Doctrine_Manager::getInstance()->getCurrentConnection();
$conn->setAttribute(Doctrine_Core::ATTR_QUOTE_IDENTIFIER, true);
Solution 3: Turn on Doctrine_Core::ATTR_QUOTE_IDENTIFIER on specific table(s) which are potentially breaking the system.
$table = Doctrine_Core::getTable('table_name');
$table->setAttribute(Doctrine_Core::ATTR_QUOTE_IDENTIFIER, true);
Note: From Doctrine 1 docs
Just because you CAN use delimited identifiers, it doesn't mean you
SHOULD use them. In general, they end up causing way more problems
than they solve. Anyway, it may be necessary when you have a reserved
word as a field name (in this case, we suggest you to change it, if
you can).