#1366 - Incorrect integer value:MYsql - mysql

hi every one i have a problem in mysql
my table is
CREATE TABLE IF NOT EXISTS `contactform` (
`contact_id` int(11) NOT NULL AUTO_INCREMENT,
`first_name` varchar(50) NOT NULL,
`addition` varchar(50) NOT NULL,
`surname` varchar(50) NOT NULL,
`Address` varchar(200) NOT NULL,
`postalcode` varchar(20) NOT NULL,
`city` varchar(50) NOT NULL,
`phone` varchar(20) NOT NULL,
`emailaddress` varchar(30) NOT NULL,
`dob` varchar(50) NOT NULL,
`howtoknow` varchar(50) NOT NULL,
`othersource` varchar(50) NOT NULL,
`orientationsession` varchar(20) NOT NULL,
`othersession` varchar(20) NOT NULL,
`organisation` int(11) NOT NULL,
`newsletter` int(2) NOT NULL,
`iscomplete` int(11) NOT NULL,
`registrationdate` date NOT NULL,
PRIMARY KEY (`contact_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=39 ;
mysql>insert into contactform values('','abhi','sir','shukla','vbxcvb','342342','asdfasd','234234234','abhi#gmail.com','1999/5/16','via vrienden of familie','','19','20','6','1','1','2010-03-29')
i get following error.
#1366 - Incorrect integer value: '' for column 'contact_id' at row 1
this query work fine on my local machine but give error on server

Had the same problem with some legacy project. I didn't want to turn off strict mode globally, but also didn't want to go through all the code to fix it, so I disabled it only within that application by executing the following query once after the connection to the db is made:
SET sql_mode = ""

Try using NULL instead of '' for contact_id in
insert into contactform values(NULL,......

Try to find following line in my.cnf/my.ini:
sql-mode=”STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION”
Now comment it out with # and restart your mysql server.

'' is an empty string, you want a integer, but this integer is created by the database. Drop the columnname in the INSERT and don't insert any value.

'' is not an integer, is it?
Also, that is some seriously weird indentation.

In mysql console, try this:
SET GLOBAL sql_mode=(SELECT REPLACE(##sql_mode,'ONLY_FULL_GROUP_BY',''));

If you are importing - make sure your CSV/TXT file is UTF-8 WITHOUT the BOM - the BOM will pass characters that are not intgers and MySQL will think you are importing that into the first field...

Related

Notice in phpmyadmin 5.0.1: Trying to access array offset on value of type bool, notice in Designer mode

I'm doing some very basic database exercises in phpMyAdmin like creating tables using SQL queries and observing it in designer mode.
But I realized there is an error shown there but when I was typing the commands to create the tables, there are no mistakes. But in designer mode, there is one line in each of my tables that is in red. The notice in the designer mode says "trying to access array offset on value of type bool".
When I ignored it and proceeded to create relations to form an ERD, I can't because the line that is in red was part of the constraint. I wonder what could be the problem. I've double-checked my queries and cross-checked the queries with my friends, drop all tables and re-create them and even re-installing xampp and phpMyAdmin. I'll add a query for one of my tables. For this particular table, the line customerName appears red in designer mode.
DROP TABLE IF EXISTS customers;
CREATE TABLE customers(
`customerNumber` int(11) NOT NULL,
`customerName` varchar(50) NOT NULL,
`contactLastName` varchar(50) NOT NULL,
`contactFirstName` varchar(50) NOT NULL,
`phone` varchar(50) NOT NULL,
`addressLine1` varchar(50) NOT NULL,
`addressLine2` varchar(50) DEFAULT NULL,
`city` varchar(50) NOT NULL,
`state` varchar(50) DEFAULT NULL,
`postalCode` varchar(15) DEFAULT NULL,
`country` varchar(50) NOT NULL,
`salesRepEmployeeNumber` int(11) DEFAULT NULL,
`creditLimit` decimal(10,2) DEFAULT NULL,
PRIMARY KEY (`customerNumber`),
KEY `salesRepEmployeeNumber` (`salesRepEmployeeNumber`))
ENGINE=InnoDB DEFAULT CHARSET=latin1;

MySQL Create Table 'closing parenthesis'

This is my sql query for MySQL:
DROP DATABASE IF EXISTS java_proj;
CREATE DATABASE java_proj
DEFAULT CHARACTER SET utf8
DEFAULT COLLATE utf8_general_ci;
USE java_proj;
CREATE TABLE Konto(
idKonto SERIAL PRIMARY KEY,
login VARCHAR(14) UNIQUE CHECK(LENGTH(login)>4) NOT NULL,
haslo VARCHAR(14) CHECK(LENGTH(haslo)>4) NOT NULL,
data_rejestracji DATE DEFAULT NOW() NOT NULL,
data_urodzenia DATE NOT NULL,
imie VARCHAR(30) NOT NULL,
nazwisko VARCHAR(30) NOT NULL
);
I'm getting error out of nowhere, in the line of login.
Error: Syntax error: 'closing parenthesis'
As mentioned in comments MySQL doesn't support CHECK.
But you also have another problem with that query: the DATE field cannot have NOW() as DEFAULT value, you can change it in DATETIME and set CURRENT_TIMESTAMP as default value
Cleaned up your query should probably look like this
CREATE TABLE Konto(
idKonto SERIAL PRIMARY KEY,
login VARCHAR(14) UNIQUE NOT NULL,
haslo VARCHAR(14) NOT NULL,
data_rejestracji DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
data_urodzenia DATE NOT NULL,
imie VARCHAR(30) NOT NULL,
nazwisko VARCHAR(30) NOT NULL
);
You can read about some workaround to the use instead of CHECK at this link
CHECK constraint in MySQL is not working

MySql Database migration

We have a large MySql table having around 400 million records, it is running on google cloud sql version 1 (MySql version 5.5).
Now google has come up with the new version of cloud sql (MySql version 5.6) ,so we want to migrate our database into this new sql version.This new version is available only on new instance. That means version 1 is on machine 1 and version 2 is on machine 2.
In this process we also made few schema changes, please check the following.
Old Schema
CREATE TABLE page_views_old (
domain varchar(50) DEFAULT NULL,
guid varchar(100) DEFAULT NULL,
sid varchar(100) DEFAULT NULL,
url varchar(2500) DEFAULT NULL,
ip varchar(20) DEFAULT NULL,
is_new varchar(20) DEFAULT NULL,
ref varchar(2500) DEFAULT NULL,
user_agent varchar(255) DEFAULT NULL,
stats_time datetime DEFAULT NULL,
country varchar(50) DEFAULT NULL,
region varchar(50) DEFAULT NULL,
city varchar(50) DEFAULT NULL,
city_lat_long varchar(50) DEFAULT NULL,
email varchar(100) DEFAULT NULL
)
New schema
CREATE TABLE page_views_new (
domain varchar(50) DEFAULT NULL,
guid binary(16) NOT NULL,
sid binary(16) NOT NULL,
url varchar(2500) DEFAULT NULL,
ip varbinary(16) NOT NULL,
is_new tinyint(4) NOT NULL,
ref varchar(2500) DEFAULT NULL,
user_agent varchar(255) DEFAULT NULL,
stats_time datetime DEFAULT NULL,
country char(2) NOT NULL,
region varchar(6) NOT NULL,
city varchar(50) DEFAULT NULL,
city_lat_long varchar(50) DEFAULT NULL,
email varchar(100) DEFAULT NULL,
id int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (id)
)
As mentioned above we changed datatype varchar to binary, varchar to varbinary, varchar to tinyint, ip to binary and others. So my question is what is best way to load this database into new instance. I didn't mention here we need to add few indexes also.
My approach for this problem
1.Take a dump of complete Database.
2.Import into new instance.
3.Modify columns one by one using alter table statements.
4.Make it live.
Can you guys please specify is there any issue with this approach and suggest me best approaches. Please mention if any issues with schema also.
Thanks

Throwing MySQLSyntaxErrorException regarding syntax of SQL in Struts

I am making a project on Struts framework.
I am getting a exception from server while inserting data in a table using SQL and I am unable to find the solution.
The error is as following:
javax.servlet.ServletException: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:
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 ',,,,,,,'yes','yes',,,,'admin')' at line 1
My code which is generating the error is as following:
sql="Insert into field_visit_details (visit_date,block,village,flw_category,
flw_name,flw_contact_no,aware_zinc,
aware_ors,past_zinc,past_ors,qty_avail_zinc_ten,qty_avail_zinc_twe,qty_avail_zinc_syr,
qty_avail_ors,qty_disp_zinc_ten,qty_disp_zinc_twe,qty_disp_zinc_syr,qty_disp_ors,
stockout_zinc,stockout_ors,diar_cases_seen,diar_cases_reff,diar_deaths_less_than_five,
added_by)
values
('"+field_visit_date+"','"+block_row_one+"','"+village_row_one+"','"+flw_category_row_one
+"','"+flw_name_row_one+"','"+flw_contact_no_row_one+"','"+aware_zinc_row_one+"','"+
aware_ors_row_one+"','"+past_zinc_row_one+"','"+past_ors_row_one+"','"+
qty_avail_zinc_ten_row_one+"','"+qty_avail_zinc_twe_row_one+"','"+
qty_avail_zinc_syr_row_one+"','"+qty_avail_ors_row_one+"','"+qty_disp_zinc_ten_row_one
+"','"+qty_disp_zinc_twe_row_one+"','"+qty_disp_zinc_syr_row_one+"','"+
qty_disp_ors_row_one+"','"+stockout_zinc_row_one+"','"+stockout_ors_row_one+
"','"+diar_cases_seen_row_one+"','"+diar_cases_reff_row_one+"','"+diar_deaths_row_one
+"','"+loginid+"')";
System.out.println(sql);
int x=stmt.executeUpdate(sql);
if(x>0)
SUCCESS="admin";
Table Structure is as following:
CREATE TABLE IF NOT EXISTS `field_visit_details` (
`field_visit_id` int(11) NOT NULL auto_increment,
`visit_date` date NOT NULL,
`block` varchar(100) NOT NULL,
`village` varchar(100) NOT NULL,
`flw_category` varchar(45) NOT NULL,
`flw_name` varchar(100) NOT NULL,
`flw_contact_no` varchar(13) NOT NULL,
`aware_zinc` varchar(10) NOT NULL,
`aware_ors` varchar(10) NOT NULL,
`past_zinc` varchar(10) NOT NULL,
`past_ors` varchar(10) NOT NULL,
`qty_avail_zinc_ten` int(11) NOT NULL,
`qty_avail_zinc_twe` int(11) NOT NULL,
`qty_avail_zinc_syr` int(11) NOT NULL,
`qty_avail_ors` int(11) NOT NULL,
`qty_disp_zinc_ten` int(11) NOT NULL,
`qty_disp_zinc_twe` int(11) NOT NULL,
`qty_disp_zinc_syr` int(11) NOT NULL,
`qty_disp_ors` int(11) NOT NULL,
`stockout_zinc` varchar(11) NOT NULL,
`stockout_ors` varchar(11) NOT NULL,
`diar_cases_seen` int(11) NOT NULL,
`diar_cases_reff` int(11) NOT NULL,
`diar_deaths_less_than_five` int(11) NOT NULL,
`added_by` varchar(100) NOT NULL,
PRIMARY KEY (`field_visit_id`) )
ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
The query when I printed in the console was :
Insert into field_visit_details (visit_date,block,village,flw_category,flw_name,
flw_contact_no,aware_zinc,aware_ors,past_zinc,past_ors,qty_avail_zinc_ten,
qty_avail_zinc_twe,qty_avail_zinc_syr,qty_avail_ors,
qty_disp_zinc_ten,qty_disp_zinc_twe,qty_disp_zinc_syr,qty_disp_ors,stockout_zinc,
stockout_ors,diar_cases_seen,diar_cases_reff,diar_deaths_less_than_five,added_by)
values
('2014-07-02','ASDASD','','asha','asd+','99','yes','yes','yes','yes',
'12','12','12','12','12','12','12','12','yes','yes','12','12','12','admin')
But the thing is that the query is inserting the data successfully in the table but still server is showing the above error.
I even used the above printed query directly in phpmyadmin and worked well without any problem.
You have a syntax exception in the SQL statement. The error message you have posted point to it.
So, you need to change SQL statement and fix syntax errors. For this purpose you should rewrite it to use PraparedStatement like in the example JDBC PreparedStatement example – Insert a record.
And use appropriate to the database column types set methods when setting parameters to the prepared statement.

MySQL ucfirst doesn't work

I have this table:
CREATE TABLE IF NOT EXISTS `events` (
`evt_id` int(11) NOT NULL AUTO_INCREMENT,
`evt_name` varchar(50) CHARACTER SET utf8 NOT NULL DEFAULT 'ucfirst',
`evt_description` varchar(100) DEFAULT NULL,
`evt_startdate` date NOT NULL,
`evt_enddate` date DEFAULT NULL,
`evt_starttime` time DEFAULT NULL,
`evt_endtime` time DEFAULT NULL,
`evt_amtpersons` int(11) DEFAULT NULL,
`sts_id` int(11) NOT NULL,
`adr_id` int(11) DEFAULT NULL,
`evt_amtPersonsSubs` tinyint(4) NOT NULL DEFAULT '0',
`evt_photo` varchar(50) DEFAULT NULL,
`sys-mut-dt` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`sys-mut-user` varchar(20) DEFAULT NULL,
`sys-mut-id` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`evt_id`),
KEY `sts_id` (`sts_id`),
KEY `adr_id` (`adr_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=12 ;
But when I add in data into evt_name my first character is not capitalized. Any ideas?
Further information:
MySQL client version: 5.1.37
I want to do this in the database so that I don't have to do ucfirst with php always.
...what?
If I'm reading this right, it will just set the default value of evt_name to the string ucfirst. Try inserting a blank row and see if I'm reading that right.
If you're really against using ucfirst in PHP, you'll probably have to still call ucfirst every time in the query. Or you could only use ucfirst on display, and not in the database.
ucfirst is a function...you defined it as Default-Value for the cell. Use it like this:
INSERT INTO events SET evt_name = UCFIRST($value)