-- phpMyAdmin SQL Dump
-- version 4.5.4.1deb2ubuntu2
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Nov 16, 2017 at 10:09 AM
-- Server version: 10.0.31-MariaDB-0ubuntu0.16.04.2
-- PHP Version: 7.1.11-1+ubuntu16.04.1+deb.sury.org+1

SET FOREIGN_KEY_CHECKS=0;
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";

--
-- Database: `development_givva`
--
CREATE DATABASE IF NOT EXISTS `development_givva` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
USE `development_givva`;

DELIMITER $$
--
-- Procedures
--
DROP PROCEDURE IF EXISTS `testProc0`$$
CREATE DEFINER=`gaAdmin`@`localhost` PROCEDURE `testProc0` ()  READS SQL DATA
BEGIN
                        SET @sqlString = 'SELECT COUNT(*) AS recordCount FROM gaTest_tst';

                        PREPARE sqlString from @sqlString;
                        EXECUTE sqlString;
                        DEALLOCATE PREPARE sqlString;
                    END$$

DROP PROCEDURE IF EXISTS `testProc1`$$
CREATE DEFINER=`gaAdmin`@`localhost` PROCEDURE `testProc1` (IN `targetValue` INT)  READS SQL DATA
BEGIN
   SET @targetVal = targetValue;

   SET @sqlString = CONCAT('
   SELECT testInteger_tst, count(*) as rowCount
   FROM gaTest_tst
   WHERE testInteger_tst is not null
   GROUP BY testInteger_tst
   HAVING rowCount > ', @targetVal, '
   ORDER BY rowCount DESC
   LIMIT 10');

   PREPARE sqlStatement FROM @sqlString;
   EXECUTE sqlStatement;
   DEALLOCATE PREPARE sqlStatement;
END$$

DROP PROCEDURE IF EXISTS `testProc2`$$
CREATE DEFINER=`gaAdmin`@`localhost` PROCEDURE `testProc2` (IN `intVal` INT, OUT `avgDouble` FLOAT, OUT `stdDevDouble` FLOAT)  READS SQL DATA
BEGIN

                       SELECT AVG(testDouble_tst), STDDEV(testDouble_tst)
                       INTO avgDouble, stdDevDouble
                       FROM gaTest_tst
                       WHERE testInteger_tst = intVal;

                    END$$

DELIMITER ;

-- --------------------------------------------------------

--
-- Table structure for table `gaTest_tst`
--

DROP TABLE IF EXISTS `gaTest_tst`;
CREATE TABLE `gaTest_tst` (
  `id_tst` int(10) UNSIGNED NOT NULL,
  `testString_tst` varchar(255) DEFAULT NULL,
  `testDouble_tst` double DEFAULT NULL,
  `testInteger_tst` int(11) DEFAULT NULL,
  `testBoolean_tst` tinyint(1) UNSIGNED DEFAULT NULL,
  `createdDate_tst` datetime DEFAULT NULL,
  `lastAccessedDate_tst` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `status_tst` varchar(32) DEFAULT NULL,
  `eventGUID_tst` char(36) DEFAULT NULL,
  `token_tst` char(36) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- --------------------------------------------------------

--
-- Stand-in structure for view `view_basic_gaTest_tst`
--
DROP VIEW IF EXISTS `view_basic_gaTest_tst`;
CREATE TABLE `view_basic_gaTest_tst` (
`token_tst` char(36)
,`testString_tst` varchar(255)
,`testDouble_tst` double
,`testInteger_tst` int(11)
,`testBoolean_tst` tinyint(1) unsigned
,`status_tst` varchar(32)
,`createdDate_tst` datetime
,`lastAccessedDate_tst` datetime
);

-- --------------------------------------------------------

--
-- Structure for view `view_basic_gaTest_tst`
--
DROP TABLE IF EXISTS `view_basic_gaTest_tst`;

CREATE ALGORITHM=UNDEFINED DEFINER=`gaAdmin`@`localhost` SQL SECURITY DEFINER VIEW `view_basic_gaTest_tst`  AS  select `gaTest_tst`.`token_tst` AS `token_tst`,`gaTest_tst`.`testString_tst` AS `testString_tst`,`gaTest_tst`.`testDouble_tst` AS `testDouble_tst`,`gaTest_tst`.`testInteger_tst` AS `testInteger_tst`,`gaTest_tst`.`testBoolean_tst` AS `testBoolean_tst`,`gaTest_tst`.`status_tst` AS `status_tst`,`gaTest_tst`.`createdDate_tst` AS `createdDate_tst`,`gaTest_tst`.`lastAccessedDate_tst` AS `lastAccessedDate_tst` from `gaTest_tst` where (`gaTest_tst`.`status_tst` <> 'DELETED') ;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `gaTest_tst`
--
ALTER TABLE `gaTest_tst`
  ADD PRIMARY KEY (`id_tst`),
  ADD UNIQUE KEY `gaTest_tst_token_tst_uindex` (`token_tst`),
  ADD KEY `gaTest_tst_createdDate_tst_status_tst_index` (`createdDate_tst`,`status_tst`),
  ADD KEY `gaTest_tst_eventGuid_tst_index` (`eventGUID_tst`),
  ADD KEY `gaTest_tst_lastAccessedDate_tst_index` (`lastAccessedDate_tst`),
  ADD KEY `testInteger_tst` (`testInteger_tst`),
  ADD KEY `testDouble_tst` (`testDouble_tst`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `gaTest_tst`
--
ALTER TABLE `gaTest_tst`
  MODIFY `id_tst` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2982;SET FOREIGN_KEY_CHECKS=1;
COMMIT;
