I need to find an open spot in the calendar (MYSQL) and allocate that time and date to a job/work order - mysql

I need to find an open date time in the future and allocate that time in the calendar for that employee based on his/her worktimes Thanks in advance
I have a calendar table, employee(recourse) table ,employee working times and jobs (with Duration)
CREATE TABLE `calendar` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`Subject` varchar(200) DEFAULT NULL,
`DateField` date DEFAULT NULL,
`EndDate` date DEFAULT NULL,
`TimeField` time DEFAULT NULL,
`EndTime` time DEFAULT NULL,
`job_id` int(11) DEFAULT NULL,
`recourse_employee_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1902 DEFAULT CHARSET=utf8;
CREATE TABLE `rc_resources_employee` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
`categoryid` int(11) DEFAULT NULL,
`login_user_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;
CREATE TABLE `jobs` (
`Job_ID` int(11) NOT NULL AUTO_INCREMENT,
`Job_Subject` varchar(150) DEFAULT NULL,
`Job_Description` mediumtext,
`Job_Start_Date` date DEFAULT NULL,
`Job_End_Date` date DEFAULT NULL,
`Job_Duration` float DEFAULT NULL,
`Job_Start_Time` time DEFAULT NULL,
`Job_End_Time` time DEFAULT NULL,
`Job_employee` int(11) DEFAULT NULL,
PRIMARY KEY (`Job_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=1875 DEFAULT CHARSET=utf8;
CREATE TABLE `work_hours` (
`wh_id` int(11) NOT NULL AUTO_INCREMENT,
`recourse_id` int(11) unsigned NOT NULL,
`wh_day_of_week` int(11) unsigned NOT NULL,
`wh_start_time` time NOT NULL,
`wh_end_time` time NOT NULL,
PRIMARY KEY (`wh_id`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8;

Related

MySQL insert using transaction

I have following structure on mysql database:
sqlfiddle
What I want to do is:
To select DISTINCT industry from Company table
To insert into Industry table first and get auto incremented ID
With this ID to insert again into IndustryTranslation table and set "language"="en"
To insert Company's id and newly generated Industry's id into MapCompanyIndustry table
I know that it's not possible with one statement. But definitely it's possible with transaction. Can't figure out how to achieve this result with one transaction.
Any suggestions?
Schema
CREATE TABLE `Industry` (
`id` int(4) unsigned NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `IndustryTranslation` (
`industryID` int(4) unsigned NOT NULL,
`language` varchar(5) NOT NULL,
`name` varchar(255) NOT NULL,
`confirmed` tinyint(1) DEFAULT '0',
PRIMARY KEY (`industryID`,`language`),
KEY `language` (`language`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `Company` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
`imageUri` varchar(255) DEFAULT NULL,
`countryID` int(3) unsigned DEFAULT NULL,
`phone` varchar(255) DEFAULT NULL,
`email` varchar(255) DEFAULT NULL,
`verified` tinyint(1) DEFAULT NULL,
`industry` varchar(255) DEFAULT NULL,
`headquarters` varchar(255) DEFAULT NULL,
`uri` varchar(255) DEFAULT NULL,
`createdAt` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`updatedAt` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `countryID` (`countryID`)
) ENGINE=InnoDB AUTO_INCREMENT=4004 DEFAULT CHARSET=utf8;
CREATE TABLE `MapCompanyIndustry` (
`companyID` int(10) unsigned NOT NULL,
`industryID` int(4) unsigned NOT NULL,
PRIMARY KEY (`companyID`,`industryID`),
KEY `industryID` (`industryID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Hibernate - How to map two tables on two columns?

I have two tables:
CREATE TABLE `framework_files` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`fileName` varchar(777) DEFAULT NULL,
`fileSize` float DEFAULT NULL,
`filePath` varchar(777) DEFAULT NULL,
`fileUrl` varchar(777) DEFAULT NULL,
`linkedObjectID` int(11) DEFAULT NULL,
`linkedObjectName` varchar(250) DEFAULT NULL,
`active` int(11) DEFAULT '0',
`uploadDate` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`uploadersIP` varchar(77) DEFAULT NULL,
`uploadersIPXFORWARDEDFOR` varchar(77) DEFAULT NULL,
`userName` varchar(777) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `q_idx` (`linkedObjectID`,`linkedObjectName`)
) ENGINE=InnoDB AUTO_INCREMENT=110 DEFAULT CHARSET=utf8;
And second table
CREATE TABLE `publicSitePortfolioWorks` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`mainName` varchar(100) DEFAULT NULL,
`tableName` varchar(250) DEFAULT 'publicSitePortfolioWorks',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;
I need to map publicSitePortfolioWorks to framework_files on framework_files.linkedObjectID=publicSitePortfolioWorks.id and framework_files.linkedObjectName=publicSitePortfolioWork.tableName .
I.e. publicSitePortfolioWorks have many objects of framework_files. All child objects must be in Set, like
private Set<FrameworkFiles> fileTEST = new HashSet<>(0);
How to map this Set in hbm.xml file? At this moment no foreign key between these two tables.

Insert All Columns from one table into another table MYSQL

I am trying to insert multiple columns with their data from one table into another table, without a common column (i would expect a cross product in the result).
I am not sure how that's possible, because each of the two tables have varied number of columns, which rules out UNION on them.
I tried a Create..Select to create a 3rd table with all columns from both the tables but unsure about the syntax (keeps throwing syntax error).
Both Tables' syntax:
CREATE TABLE `t_modul` (
`ID` int(11) NOT NULL,
`Seriennummer` int(11) DEFAULT NULL,
`Bezeichnung` varchar(128) DEFAULT NULL,
`StandortID` int(11) NOT NULL,
`Firmwareversion` varchar(8) DEFAULT NULL,
`Optionen` int(11) DEFAULT NULL,
`Feldstärke` int(11) DEFAULT NULL,
`Platziert` bit(1) DEFAULT NULL,
`Sendeintervall` int(11) DEFAULT NULL,
`Batteriekapazitaet` int(11) DEFAULT NULL,
`Modulzusatzinfo` varchar(255) DEFAULT NULL,
`ModulUserinfo` varchar(128) DEFAULT NULL,
`ReadOutDate` varchar(40) DEFAULT NULL,
`ReduktionsIntervall` int(11) DEFAULT NULL,
`Startdatum` varchar(40) DEFAULT NULL,
`SAMTemperaturEin` double DEFAULT NULL,
`SAMTemperaturAus` double DEFAULT NULL,
`SAMCoolingOff` int(11) DEFAULT NULL,
`SAMCoolingOn` int(11) DEFAULT NULL,
`SAMCoolingOffMax` double DEFAULT NULL,
`SAMCoolingOnMin` double DEFAULT NULL,
`SAMParameterField` int(11) DEFAULT NULL,
`SAMIsAlarmMelder` bit(1) DEFAULT NULL,
`SAMNv27` int(11) DEFAULT NULL,
`Hardwarekonfiguration` int(11) DEFAULT NULL,
`Anwendungskonfiguration` int(11) DEFAULT NULL,
`Logkonfiguration` int(11) DEFAULT NULL,
`Archivsendezeit_0` int(11) DEFAULT NULL,
`Archivsendezeit_1` int(11) DEFAULT NULL,
`IsLogger` bit(1) DEFAULT NULL,
`Datenpunktkennung` varchar(128) DEFAULT NULL,
`TTRFtpARCHPollDoneDate` varchar(40) DEFAULT NULL,
`Repeaternummer` int(11) DEFAULT NULL,
`StammdatenID` int(11) DEFAULT NULL,
PRIMARY KEY (`ID`),
KEY `ID_Standort_idx` (`StandortID`),
CONSTRAINT `ID_StandOrt` FOREIGN KEY (`StandortID`) REFERENCES `t_standorte` (`ID`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `sensors` (
`sensorID` bigint(11) NOT NULL,
`Number` bigint(20) unsigned NOT NULL,
`ValueIDs` text NOT NULL,
`MeasureTime` datetime NOT NULL,
`StartTime` datetime NOT NULL,
`Configuration` int(10) unsigned NOT NULL,
`LogCycle` int(11) NOT NULL,
`Alarms` text NOT NULL,
`AlarmType` int(11) NOT NULL,
PRIMARY KEY (`GesySenseID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
UNION query:
CREATE TABLE sensors_1
SELECT * FROM `sensors`
UNION
SELECT * FROM `t_modul`;
could someone help me out?
thank you
CREATE TABLE sensors_1
AS (SELECT * FROM `sensors`
UNION
SELECT * FROM `t_modul`);
this answer suggested to me worked:
CREATE TABLE t_cross_result AS
SELECT *
FROM t_modul CROSS JOIN sensors

What's the best way to move MySQL to Parse.com

I have an iOS app that currently uses MySQL as the database backend to store about 2000 records and 10,000 photos. I want to refactor my Objective-C to use Parse instead of the current MySQL and I'm wondering what would be the best way to move my MySQL data to Parse?
Here is the current MySQL structure of my database.
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
--
-- Database: `mysqlToParsePlatform`
--
-- --------------------------------------------------------
--
-- Table structure for table `awesome_authentication`
--
CREATE TABLE `awesome_authentication` (
`authentication_id` int(11) NOT NULL auto_increment,
`username` varchar(100) NOT NULL,
`password` varchar(100) NOT NULL,
`name` varchar(100) NOT NULL,
`role_id` int(11) NOT NULL,
`is_deleted` int(11) NOT NULL,
`deny_access` int(11) NOT NULL,
PRIMARY KEY (`authentication_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=6 ;
-- --------------------------------------------------------
--
-- Table structure for table `awesome_categories`
--
CREATE TABLE `awesome_categories` (
`category_id` int(11) NOT NULL auto_increment,
`category` varchar(100) NOT NULL,
`category_icon` varchar(100) NOT NULL,
`created_at` int(11) NOT NULL,
`updated_at` int(11) NOT NULL,
`is_deleted` int(11) NOT NULL,
PRIMARY KEY (`category_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;
-- --------------------------------------------------------
--
-- Table structure for table `awesome_news`
--
CREATE TABLE `awesome_news` (
`news_id` int(11) NOT NULL auto_increment,
`news_content` text NOT NULL,
`news_title` varchar(100) NOT NULL,
`news_url` varchar(100) NOT NULL,
`photo_url` varchar(200) NOT NULL,
`created_at` int(11) NOT NULL,
`updated_at` int(11) NOT NULL,
`is_deleted` int(11) NOT NULL,
PRIMARY KEY (`news_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;
-- --------------------------------------------------------
--
-- Table structure for table `awesome_photos`
--
CREATE TABLE `awesome_photos` (
`photo_id` int(11) NOT NULL auto_increment,
`photo_url` varchar(200) NOT NULL,
`thumb_url` varchar(200) NOT NULL,
`store_id` int(11) NOT NULL,
`created_at` int(11) NOT NULL,
`updated_at` int(11) NOT NULL,
`is_deleted` int(11) NOT NULL,
PRIMARY KEY (`photo_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=10167 ;
-- --------------------------------------------------------
--
-- Table structure for table `awesome_ratings`
--
CREATE TABLE `awesome_ratings` (
`rating_id` int(11) NOT NULL auto_increment,
`rating` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
`created_at` int(11) NOT NULL,
`updated_at` int(11) NOT NULL,
`store_id` int(11) NOT NULL,
PRIMARY KEY (`rating_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=32 ;
-- --------------------------------------------------------
--
-- Table structure for table `awesome_reviews`
--
CREATE TABLE `awesome_reviews` (
`review_id` int(11) NOT NULL auto_increment,
`review` text NOT NULL,
`store_id` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
`created_at` int(11) NOT NULL,
`updated_at` int(11) NOT NULL,
`is_deleted` int(11) NOT NULL,
PRIMARY KEY (`review_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;
-- --------------------------------------------------------
--
-- Table structure for table `awesome_stores`
--
CREATE TABLE `awesome_stores` (
`store_id` int(11) NOT NULL auto_increment,
`store_name` varchar(100) NOT NULL,
`store_address` varchar(160) NOT NULL,
`store_desc` text NOT NULL,
`lat` varchar(20) NOT NULL,
`lon` varchar(20) NOT NULL,
`sms_no` varchar(30) NOT NULL,
`phone_no` varchar(30) NOT NULL,
`email` varchar(30) NOT NULL,
`website` varchar(100) NOT NULL,
`category_id` int(11) NOT NULL,
`created_at` int(11) NOT NULL,
`updated_at` int(11) NOT NULL,
`featured` int(11) NOT NULL,
`is_deleted` int(11) NOT NULL,
PRIMARY KEY (`store_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=2027 ;
-- --------------------------------------------------------
--
-- Table structure for table `awesome_users`
--
CREATE TABLE `awesome_users` (
`user_id` int(11) NOT NULL auto_increment,
`full_name` varchar(100) NOT NULL,
`username` varchar(40) NOT NULL,
`password` varchar(40) NOT NULL,
`login_hash` varchar(200) NOT NULL,
`facebook_id` text NOT NULL,
`twitter_id` text NOT NULL,
`email` varchar(100) NOT NULL,
`deny_access` int(11) NOT NULL,
`thumb_url` varchar(100) NOT NULL,
`photo_url` varchar(100) NOT NULL,
PRIMARY KEY (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=19 ;
After spending a lot of time looking for answers, trying to research migration services and looking into writting custom scripts, I decided to try the easiest route first. And that worked!
Hopefully this will help others looking to move similar records from MySQL to Parse.
In order to get my 2,000+ stores records and 10,000+ photos out of the MySQL database, I went to phpMyAdmin and exported the awesome_stores and awesome_photos tables to two separate CSV files using the setting pictured below.
Once you have your CSV files, open your Parse Data Browser and go to the Core tab and look under the Data section pictured below and click on Import.
That will bring up the import dialog box. That looks like this. Name your new Custom Class and then add your .CSV. Make sure that phpMyAdmin does not add an extra line to head of your .csv. If it does, you will get an error when trying to do the import to Parse.

Suggestion for faster select query

I have a table
CREATE TABLE `partially_allowed` (
`service_area_code` int(2) DEFAULT NULL,
`number` varchar(20) DEFAULT NULL,
`phone_type` int(1) DEFAULT NULL,
`date_created` datetime DEFAULT NULL,
`preference` varchar(10) DEFAULT NULL,
KEY `idx_number` (`number`(4))
) ENGINE=InnoDB DEFAULT CHARSET=latin1
having 29,731,330 rows. I need to join this with another table
CREATE TABLE `data_from_files` (
`mobile` varchar(10) DEFAULT NULL,
`city` varchar(50) DEFAULT NULL,
`pin` varchar(10) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1
having over 10,000,000 rows.
What is the best possible index for a fast select query?