ERROR 1064 (42000) on mysql when creating a table - mariadb

MariaDB [(none)]>
MariaDB [(none)]> create database isathub
-> CREATE TABLE `tab_access` (
-> `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
-> `isApp` TINYINT(1) NOT NULL DEFAULT '1',
-> `datetime` DATETIME NOT NULL,
-> `lat` VARCHAR(100) DEFAULT NULL,
-> `long` VARCHAR(100) DEFAULT NULL,
-> `category` VARCHAR(250) DEFAULT NULL,
-> `name` VARCHAR(250) DEFAULT NULL,
-> `url` VARCHAR(250) DEFAULT NULL,
-> `os` VARCHAR(100) DEFAULT NULL,
-> `imei` VARCHAR(100) DEFAULT NULL,
-> `apn` VARCHAR(100) DEFAULT NULL,
-> PRIMARY KEY (`id`)
->
-> ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
I am getting the error:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'CREATE TABLE `tab_access` (
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`isAp' at line 2
I Don't know what it wrong.

Your create table statement looks fine, but you didn't put a semicolon after:
create database isathub
So it didn't execute that statement, and thinks the create table statement is part of the create database statement.

syntax:
create database database_name;
now you can create table
create table 'table_name'();

Related

Syntax Error when I try to create trigger in mysql

I am trying to create an trigger for an audit log, where after an insert into manageMemberLog and the action column is equal to CREATE, then insert the associate columns of users table and then grab the select the newly created row and grab the userID and then insert the rest of the data into profile, but I get this error msg when I tried to submit the query.
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'END' at line 9
Line 9 = END IF;
I tried carefully re-typing what I wrote but same error msg.
UPDATE: used the formatting and it says WHERE userID = #newUserID is the error, which i still don't understand as I grab the data from select and set the value into #newUserID.
DELIMITER $$
CREATE TRIGGER usersDB_ai AFTER INSERT
ON manageMemberLog
FOR EACH ROW
IF NEW.action = 'CREATE' THEN
INSERT INTO users (firstName, lastName, userName, email, pwd) VALUES (NEW.firstName, NEW.lastName, NEW.userName, NEW.email, NEW.pwd);
SET #newUserID := (SELECT userID FROM users WHERE userName = NEW.userName AND email = NEW.email);
UPDATE profiles SET rankID = NEW.rankID WHERE userID = #newUserID;
END IF;
END$$
DELIMITER ;
The related tables:
CREATE TABLE `users` (
`userID` int(11) NOT NULL,
`firstName` varchar(128) NOT NULL,
`lastName` varchar(128) NOT NULL,
`userName` varchar(128) NOT NULL,
`email` varchar(128) NOT NULL,
`pwd` varchar(128) NOT NULL
)
DELIMITER $$
CREATE TRIGGER `userCreated` AFTER INSERT ON `users` FOR EACH ROW BEGIN
INSERT INTO profiles (userID) VALUES(NEW.userID);
END
$$
DELIMITER ;
CREATE TABLE `profiles` (
`profileID` int(11) NOT NULL,
`userID` int(11) NOT NULL,
`rankID` int(11) NOT NULL,
...
)
CREATE TABLE `manageMemberLog` (
`manageMemberLogID` int(11) NOT NULL,
`manageDate` datetime NOT NULL,
`managerID` int(11) DEFAULT NULL,
`action` varchar(6) CHARACTER SET utf8mb4 NOT NULL,
`userID` int(11) DEFAULT NULL,
`firstName` varchar(128) CHARACTER SET utf8mb4 NOT NULL,
`lastName` varchar(128) CHARACTER SET utf8mb4 NOT NULL,
`userName` varchar(128) CHARACTER SET utf8mb4 NOT NULL,
`email` varchar(128) CHARACTER SET utf8mb4 NOT NULL,
`pwd` varchar(128) CHARACTER SET utf8mb4 NOT NULL,
`rankID` int(11) NOT NULL
)
Can anyone help thanks in advance!
Silly Me, so what went wrong is I forgot to write "BEGIN" after FOR EACH ROW and does not involve any of the error that it says. Error messages are sometimes not reliable but I guess it did help by say END. A better error message is you can't end when it never began.
so correct query is:
DELIMITER $$
CREATE TRIGGER usersDB_ai AFTER INSERT
ON manageMemberLog
FOR EACH ROW BEGIN
IF NEW.action = 'CREATE' THEN
INSERT INTO users (firstName, lastName, userName, email, pwd) VALUES (NEW.firstName, NEW.lastName, NEW.userName, NEW.email, NEW.pwd);
SET #newUserID := (SELECT userID FROM users WHERE userName = NEW.userName AND email = NEW.email);
UPDATE profiles SET rankID = NEW.rankID WHERE userID = #newUserID;
END IF;
END$$
DELIMITER ;

ERROR: Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server

So I keep having this error on my sql
ERROR: Error 1064: You have an error in your SQL syntax; check the
manual that corresponds to your MariaDB server version for the right
syntax to use near ' CONSTRAINT fk_examinee_user1
FOREIGN KEY (userName)
REFERENCES `q' at line 12
SQL Code:
-- -----------------------------------------------------
-- Table `questionnaire`.`examinee`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `questionnaire`.`examinee` (
`examineeNumber` INT NOT NULL,
`userName` VARCHAR(45) NOT NULL,
`examineeID` VARCHAR(45) NOT NULL,
`startDate` INT NOT NULL,
`endDate` INT NOT NULL,
`Active` VARCHAR(45) NOT NULL,
PRIMARY KEY (`examineeID`),
INDEX `fk_examinee_user1_idx` (`userName` ASC) VISIBLE,
CONSTRAINT `fk_examinee_user1`
FOREIGN KEY (`userName`)
REFERENCES `questionnaire`.`user` (`userName`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
Tried everything but code seems right to me. please help

Cannot convert Query with Subquery to Symfony Doctrine QueryBuilder

I have a query that does what is required
SELECT v.* FROM vehicle v
WHERE v.company_id = 2 AND v.id NOT IN
(
SELECT h.vehicle_id
FROM hire h
WHERE
h.start_date is not null and h.end_date is null
)
So now I am trying to code this query in Symfony/Doctrine
I have this
$qb = $this->_em->createQueryBuilder();
$subq = $this->_em->createQueryBuilder();
$subq ->select('h.vehicle')
->from('AppBundle\Entity\Hire', 'h')
->andWhere('h.startDate is not null and h.endDate is null');
$qb->select('v')
->from('AppBundle\Entity\Vehicle', 'v')
->where($qb->expr()->notIn('v.id',$subq->getDQL()))
->andWhere('v.company = :company')
->setParameter('company', $company)
->orderBy('v.registrationNumber', 'ASC')
;
$t = $qb->getDQL();
return $qb;
As you see I tried dumping the DQL to see if that gave me any clues and here is is
SELECT v
FROM AppBundle\Entity\Vehicle v
WHERE (v.id NOT IN(SELECT h.vehicle FROM AppBundle\Entity\Hire h WHERE h.startDate is not null and h.endDate is null))
AND v.company = :company
ORDER BY v.registrationNumber ASC
I tried converting this back to simple SQL i.e. removing the AppBundle stuff and converting the column names back to actual column name and it runs and get the right result.
But I am getting this error
Doctrine\ORM\Query\QueryException:
[Semantical Error] line 0, col 69 near 'vehicle FROM': Error: Invalid PathExpression. Must be a StateFieldPathExpression.
at vendor\doctrine\orm\lib\Doctrine\ORM\Query\QueryException.php:63
at Doctrine\ORM\Query\QueryException::semanticalError('line 0, col 69 near \'vehicle FROM\': Error: Invalid PathExpression. Must be a StateFieldPathExpression.', object(QueryException))
The 2 tables involved are
CREATE TABLE `hire` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`company_id` int(11) DEFAULT NULL,
`driver_id` int(11) DEFAULT NULL,
`vehicle_id` int(11) DEFAULT NULL,
`corporate_hire` tinyint(1) DEFAULT NULL,
`end_date` datetime DEFAULT NULL,
`end_miles` decimal(10,1) DEFAULT NULL,
`start_date` datetime DEFAULT NULL,
`start_miles` decimal(10,1) DEFAULT NULL,
`created_by` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`updated_by` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`deleted_by` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`deleted_at` datetime DEFAULT NULL,
`created_at` datetime DEFAULT NULL,
`updated_at` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `IDX_B8017EFC979B1AD6` (`company_id`),
KEY `IDX_B8017EFCC3423909` (`driver_id`),
KEY `IDX_B8017EFC545317D1` (`vehicle_id`),
CONSTRAINT `FK_B8017EFC545317D1` FOREIGN KEY (`vehicle_id`) REFERENCES `vehicle` (`id`) ON DELETE SET NULL,
CONSTRAINT `FK_B8017EFC979B1AD6` FOREIGN KEY (`company_id`) REFERENCES `company` (`id`) ON DELETE SET NULL,
CONSTRAINT `FK_B8017EFCC3423909` FOREIGN KEY (`driver_id`) REFERENCES `driver` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
and
CREATE TABLE `vehicle` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`company_id` int(11) DEFAULT NULL,
`storage_id` int(11) DEFAULT NULL,
`created_by` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`updated_by` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`deleted_by` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`deleted_at` datetime DEFAULT NULL,
`created_at` datetime DEFAULT NULL,
`updated_at` datetime DEFAULT NULL,
`date_of_manufacture` datetime DEFAULT NULL,
`engine_size` int(11) DEFAULT NULL,
`make` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`model` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`registration_number` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
`vin` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `IDX_1B80E486979B1AD6` (`company_id`),
KEY `IDX_1B80E4865CC5DB90` (`storage_id`),
CONSTRAINT `FK_1B80E4865CC5DB90` FOREIGN KEY (`storage_id`) REFERENCES `storage` (`id`) ON DELETE SET NULL,
CONSTRAINT `FK_1B80E486979B1AD6` FOREIGN KEY (`company_id`) REFERENCES `company` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
I am not sure what an Invalid Path Expression should be making me look for as an actual error.
What's working for us is (adapted to your example, so not tested):
$subQuery->select('IDENTITY(h.vehicle)');
$subQuery->from('AppBundle\Entity\Hire', 'h');
$dqlString = $subQuery->getQuery()->getDQL();
$query->andWhere('v.id' 'NOT IN (' . $dqlString . ')');
The only two differences that I see are:
subQuery returns IDENTITY() of h.vehicle, so only the 'identifier' (which is id in most cases)
our andWhere condition in main query is created manually - but your expression builder should work the same way.
So my assumption ist that your $subq ->select('h.vehicle') doesn't return ids which can be used in the NOT IN condition of your main query, which might be proven by your resolved DQL SELECT v : this will return all fields, but you'd required v.id only.

Warning: spl_object_hash() expects parameter 1 to be object

Warning: spl_object_hash() expects parameter 1 to be object, string given in
/var/www/sitetwo/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php line 1367
I created MainBlogBundle with Category.php and Product.php using yml mapping annotation via php app/console commands. After using CRUD actions for add/edit/delete/show actions I tried to add a category and after submitting Add category form I get the
Warning: spl_object_hash() expects parameter 1 to be object, string given in
/var/www/sitetwo/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php line 1367
I posted my sample code on github and below is the script of database.
git#github.com:veerpartap/ProblemSymfony.git
/****************************************************************************/
-- phpMyAdmin SQL Dump
-- version 3.4.10.1deb1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Oct 26, 2013 at 01:56 PM
-- Server version: 5.5.32
-- PHP Version: 5.5.3-1+debphp.org~precise+2
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
--
-- Database: `sitetwo`
--
-- --------------------------------------------------------
--
-- Table structure for table `category`
--
CREATE TABLE IF NOT EXISTS `category` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
-- --------------------------------------------------------
--
-- Table structure for table `Company`
--
CREATE TABLE IF NOT EXISTS `Company` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`company_name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`address` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`owner_name` varchar(150) COLLATE utf8_unicode_ci NOT NULL,
`status` tinyint(1) NOT NULL,
`created` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=3 ;
--
-- Dumping data for table `Company`
--
INSERT INTO `Company` (`id`, `company_name`, `address`, `owner_name`, `status`, `created`) VALUES
(1, 'My First Company', 'Street 5A Sector 85 Chandigarh 1665588', 'Mr. Prateek Kumar', 1, '2013-09-06 00:00:00'),
(2, 'My Second Private Company', 'Street 34N Sector 89, Chandigarh 165898', 'Mr. Saurabh Shuja', 1, '2013-09-07 00:00:00');
-- --------------------------------------------------------
--
-- Table structure for table `Post`
--
CREATE TABLE IF NOT EXISTS `Post` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(250) COLLATE utf8_unicode_ci NOT NULL,
`body` longtext COLLATE utf8_unicode_ci NOT NULL,
`published` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
-- --------------------------------------------------------
--
-- Table structure for table `posts`
--
CREATE TABLE IF NOT EXISTS `posts` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(250) COLLATE utf8_unicode_ci NOT NULL,
`body` longtext COLLATE utf8_unicode_ci NOT NULL,
`published` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
-- --------------------------------------------------------
--
-- Table structure for table `products`
--
CREATE TABLE IF NOT EXISTS `products` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`category_id` int(11) DEFAULT NULL,
`name` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`price` decimal(10,0) NOT NULL,
`description` longtext COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`),
KEY `IDX_B3BA5A5A12469DE2` (`category_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
-- --------------------------------------------------------
--
-- Table structure for table `User`
--
CREATE TABLE IF NOT EXISTS `User` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`first_name` varchar(150) NOT NULL,
`last_name` varchar(150) NOT NULL,
`sex` tinyint(1) DEFAULT NULL,
`date_of_birth` datetime DEFAULT NULL,
`education` varchar(10) NOT NULL,
`mobile` varchar(10) NOT NULL,
`email` varchar(100) NOT NULL,
`address` varchar(200) NOT NULL,
`status` tinyint(1) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
--
-- Dumping data for table `User`
--
INSERT INTO `User` (`id`, `first_name`, `last_name`, `sex`, `date_of_birth`, `education`, `mobile`, `email`, `address`, `status`) VALUES
(1, 'Veerpartap', 'Singh', 1, '2008-11-24 00:00:00', 'MCA', '71505897', 'metveerpartapsingh#gmail.com', 'hl 99 phase 2 sas nagar mohali', 1),
(2, 'Vicky', 'Sharma', 1, '2008-05-09 00:00:00', 'MCA', '88754257', 'vicky.sharma#gmail.com', 'Village Burari, Jila Nawanshar', 1);
--
-- Constraints for dumped tables
--
--
-- Constraints for table `products`
--
ALTER TABLE `products`
ADD CONSTRAINT `FK_B3BA5A5A12469DE2` FOREIGN KEY (`category_id`) REFERENCES `category` (`id`);
/****************************************************************************/
As stated in the above comment, the issue was about that I am not including the Arrarycollection namespace in the controller file. But after including the namespace I get another error while adding new products.
Below is the error message :
"__toString()" method was not foudn on the object of type Main\BlogBundle\Enity\Category to the choice field.
For this error, We need to add a __toString() method to your Category entity. For example:
public function __toString() { return $this->name; }
The PHP magic-method __toString() is used to present a textual representation of the object. In this case, the Category name will be used when selecting a Category in a Form of a related entity.
if you getthe __toString() error in a class XxxxxType extends AbstractType
you can add the fiel definition in the builder, like this. No need to modify your entity.
$builder
->add('enquete','entity',array('class' => 'AdequatSipBundle:Enquete',
'property' => 'Id', 'read_only'=>true))
->add('produit','entity',array('class' => 'AdequatSipBundle:Produit',
'property' => 'Name', 'read_only'=>true))

#1062 - Duplicate entry '1' for key 'PRIMARY'

I am importing database and i got an error
1062 - Duplicate entry '1' for key PRIMARY.
i tried to upload table individually But it gives me error for those table which have at least one row.
i don't want to delete any record of any table.
here is one table which is giving error.
CREATE TABLE IF NOT EXISTS `wpbeta_aff_affiliates` (
`affiliate_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL,
`email` varchar(512) DEFAULT NULL,
`from_date` date NOT NULL,
`thru_date` date DEFAULT NULL,
`status` varchar(10) NOT NULL DEFAULT 'active',
`type` varchar(10) DEFAULT NULL,
PRIMARY KEY (`affiliate_id`),
KEY `affiliates_afts` (`affiliate_id`,`from_date`,`thru_date`,`status`),
KEY `affiliates_sft` (`status`,`from_date`,`thru_date`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;
--
-- Dumping data for table `wpbeta_aff_affiliates`
--
INSERT INTO `wpbeta_aff_affiliates` (`affiliate_id`, `name`, `email`, `from_date`, `thru_date`, `status`, `type`) VALUES
(1, 'Direct', NULL, '2013-07-03', NULL, 'active', 'direct');
You do not need to specify the record id (with the exception of some circumstances when you need to keep the connection between records in different tables). Try using this query:
INSERT INTO wpbeta_aff_affiliates (name, email, from_date, thru_date, status, type) VALUES ('Direct', NULL, '2013-07-03', NULL, 'active', 'direct');

Resources