 DELIMITER $$
/* ************************************************************************************************************************************************************************
	sys_browsers_SQL
************************************************************************************************************************************************************************ */	
		DROP PROCEDURE IF EXISTS `_Prepare_Browser_SQLText`$$
		
		
				DROP FUNCTION IF EXISTS `_ConcatSQLPreSeq`$$
				CREATE DEFINER=`root`@`localhost` FUNCTION `_ConcatSQLPreSeq`(
					_Comment VARCHAR(200),
					_Value TEXT,
					_Param_A VARCHAR(256)
				) RETURNS TEXT -- VARCHAR(1020)
					NO SQL
					DETERMINISTIC
				BEGIN
					SET @._Comment = _Comment, @._Value = _Value;
					SET @._ConcatSQLPreSeq = 
						CONCAT(
						'/*** ', @._Comment, ' ***/\n', @._Value
					);
					IF _Param_A LIKE '%TAB%' THEN 
						RETURN REPLACE(@._ConcatSQLPreSeq, '\n', '\n\t');
					ELSE
						RETURN @._ConcatSQLPreSeq;
					END IF;
				END$$
				 
				DROP FUNCTION IF EXISTS `_ConcatSQLPreSeqPost`$$
				CREATE DEFINER=`root`@`localhost` FUNCTION `_ConcatSQLPreSeqPost`(
					_Comment VARCHAR(200),
					_Pre VARCHAR(50),
					_Value TEXT,
					_Post VARCHAR(50),
					_Param_A VARCHAR(256)
				) RETURNS TEXT -- VARCHAR(1020)
					NO SQL
					DETERMINISTIC
				BEGIN
					IF IFNULL(_Value, '') = '' THEN
						SET @._ConcatSQLPreSeqPost = NULL;
					ELSE
						SET @.TAB = _Param_A LIKE '%TAB%', @._Comment = _Comment; 
						SET @._Value = 
							IF(@.TAB,
								CONCAT('\t', REPLACE(_Value, '\n', '\n\t')),
								_Value
							)
						;
						-- SET @._ConcatSQLPreSeqPost = 
						-- 	CONCAT_WS('\n',
						-- 		CONCAT('/*** ', @._Comment, ' ***/'),
						-- 		NULLIF(_Pre, ''), 
						-- 		@._Value, 
						-- 		NULLIF(_Post, '')
						-- 	)
						-- ;
						SET @._ConcatSQLPreSeqPost = 
							CONCAT_WS('',
								CONCAT('/*** ', @._Comment, ' ***/\n'),
								NULLIF(_Pre, ''), 
								@._Value, 
								NULLIF(_Post, '')
							)
						;
					END IF;
					RETURN @._ConcatSQLPreSeqPost;
				END$$
				 
				DROP FUNCTION IF EXISTS `_SQL_FMT_Stat`$$
				CREATE DEFINER=`root`@`localhost` FUNCTION `_SQL_FMT_Stat`(
					_MODE VARCHAR(200),
					_Template VARCHAR(200),
					_KeyWord VARCHAR(200),
					_Pre VARCHAR(50),
					_Value TEXT,
					_ValueTab BOOLEAN,
					_Post VARCHAR(50),
					-- _ShowComment BOOLEAN,
					_ValueIfNULL VARCHAR(256)
				) RETURNS TEXT -- VARCHAR(1020)
					NO SQL
					DETERMINISTIC
				BEGIN
					IF _MODE = 'RESET' OR @.SQL.FS.Default1 IS NULL THEN 
						SET
							@.SQL.FS.Default1 = 		'/*** #COMMENT# ***/\n#CONTENT#',
							@.SQL.FS.Default2 = 		'/*** #COMMENT# ***/\n#PRE##CONTENT##POST#',
							@.SQL.FS.FROM =	 			'/*** FROM ***/\n#PRE##CONTENT##POST#',
							@.SQL.FS.JOIN =	 			'/*** JOIN ***/\n#PRE##CONTENT##POST#',
							@.SQL.FS.WHERE 	= 			'/*** WHERE ***/\nWHERE\n#PRE##CONTENT##POST#',
							@.SQL.FS.WHERE.S =	 		'/*** WHERE staly browsera ***/\n#PRE##CONTENT##POST#',
							@.SQL.FS.WHERE.S.ADD =		'/*** WHERE alternatywny browsera dodatkowy ***/\n#PRE##CONTENT##POST#',
							@.SQL.FS.WHERE.V =	 		'/*** WHERE alternatywny aktualnego widoku ***/\n#PRE##CONTENT##POST#',
							@.SQL.FS.WHERE.P =	 		'/*** WHERE alternatywny filtrow ***/\n#PRE##CONTENT##POST#',
							@.SQL.FS.WHERE.Key = 		'/*** WHERE dla refresh Key ***/\n#PRE##CONTENT##POST#',
							@.SQL.FS.WHERE.MaxTime =	'/*** WHERE dla refresh time ***/\n#PRE##CONTENT##POST#',
							
							@.SQL.FS.GROUP =			'\n#KeyWord# #CONTENT#',
							@.SQL.FS.HAVING = 			'\n/*** HAVING ***/\n#KeyWord# #PRE##CONTENT##POST#',
							@.SQL.FS.ORDER =			'\n#KeyWord# #CONTENT#',
							
							@.SQL.FS.Ext1 = ',\n/*** Pole REC_OK gdy tryb refresh key lub refresh time ***/\n#(##PRE##CONTENT##POST##)# AS REC_OK',
							@.SQL.FS.Ext2 = '/*** COMMENT ***/\n',
							@.SQL.FS.LIMIT =			'\n#CONTENT#',
							@.SQL.FS.Empty =		'#CONTENT#'
						;
						RETURN 'OK';
					END IF;
					IF _MODE IN ('', 'FMT') THEN
						SET 
							@._Value.IS.NULL = (@._Value := NULLIF(_Value, '')) IS NULL
						;
						IF IFNULL(@._Value, '') = '' THEN
							SET @._SQL_FMT_Stat = IFNULL(@._Value, _ValueIfNULL);
						ELSE
							SET
								@.Value.has.1.Line = LOCATE('\n', @._Value) = 0
							;	
							SET 
								@.TAB = 
									_ValueTab = 1 OR 
									_ValueTab = 2 AND NOT @.Value.has.1.Line 
								-- @._Comment = _Comment
							; 
							SET 
								@._Value = 
								IF(@.TAB,
									CONCAT('\t', REPLACE(_Value, '\n', '\n\t')),
									_Value
								)
							;
							SET @._SQL_FMT_Stat = 
								REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(_Template,
									-- '#COMMENT#', _Comment),
									'#KeyWord#\n', CONCAT(_KeyWord, '\n')),
									'#KeyWord#', CONCAT(_KeyWord, IF(@.Value.has.1.Line, '', '\n'))),
									'#(#', IF(@.Value.has.1.Line, '(', '(\n')),
									'#)#', IF(@.Value.has.1.Line, ')', '\n)')),
									'#PRE#', _Pre),
									'#CONTENT#', @._Value),
									'#POST#', _Post)
							;		
						END IF;
						RETURN @._SQL_FMT_Stat;
					END IF;
				END$$		

DROP PROCEDURE IF EXISTS `_SQL_Exe`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `_SQL_Exe`(
	IN _MODE VARCHAR(250),
	IN _Key VARCHAR(150),	
	IN _Key2 VARCHAR(150),	
	IN _Key3 VARCHAR(150),	
	INOUT _SQL MEDIUMTEXT,
	IN _Param_A VARCHAR(250),	
	IN _Param_B VARCHAR(250),	
	IN _Param_C VARCHAR(250),	
	IN _Param_D VARCHAR(250),
	IN _Param_E VARCHAR(250)	
)
/*
*/

S_SQL_Exe: BEGIN 

	DECLARE	_Id_browser, _ID_SQL, _Context VARCHAR(150);
	DECLARE	_Limit, _MaxTime VARCHAR(250);
	DECLARE _PrfGUID_c, _PrfGUID_f, _PrfGUID_p, _PrfGUID_d VARCHAR(38);

	IF _MODE = 'Init.Rec' THEN
		REPLACE INTO `t_browser.sql.prepare` 
		(ID_SECT, Kind, _id_browser)
		VALUES
		('vvvv', 'laddd', '34445')
		;		
	END IF;



			IF _MODE = 'SQL.CREATE.t_browser.sql.prepare' THEN
				DROP TEMPORARY TABLE IF EXISTS `t_browser.sql.prepare`;
				CREATE TEMPORARY TABLE `t_browser.sql.prepare` (
					`ID_SECT` VARCHAR(38) NOT NULL DEFAULT '' COMMENT 'Klucz glowny',
					`Kind` VARCHAR(150) NOT NULL DEFAULT '' COMMENT 'Kind z sql',
					`Context` VARCHAR(150) NOT NULL DEFAULT 'select' COMMENT 'np. information_schema',
					`Id_browser` VARCHAR(38) NOT NULL DEFAULT '' COMMENT 'Klucz browsera',
					`View` VARCHAR(38) NOT NULL DEFAULT '' COMMENT 'view przegladarki',
					
					`SQL.Body` MEDIUMTEXT COMMENT 'Sam select',
					`SQL.Body.Agg` MEDIUMTEXT COMMENT 'Sam select',
					`SQL.Body.MaxTime` MEDIUMTEXT COMMENT 'Sam select',
					`SQL.Body.Key` MEDIUMTEXT COMMENT 'Sam select',
					`SQL.Body.Schema` MEDIUMTEXT COMMENT 'Sam select',
					`SQL.Exe` MEDIUMTEXT COMMENT 'Zwykly select / call',
					`SQL.Exe.Temporary` MEDIUMTEXT COMMENT 'temporarka',
					`SQL.DROP.Temporary` MEDIUMTEXT COMMENT 'temporarka',
					`SQL.CREATE.Temporary` MEDIUMTEXT COMMENT 'temporarka',
					`SQL.DROP.Temporary.Check` MEDIUMTEXT COMMENT 'temporarka',
					`SQL.CREATE.Temporary.Check` MEDIUMTEXT COMMENT 'temporarka',
					`SQL.DROP.Temporary.maxtime` MEDIUMTEXT COMMENT 'temporarka',
					`SQL.CREATE.Temporary.maxtime` MEDIUMTEXT COMMENT 'temporarka',
					`SQL.DROP.Temporary.key` MEDIUMTEXT COMMENT 'temporarka',
					`SQL.CREATE.Temporary.key` MEDIUMTEXT COMMENT 'temporarka',
					`SQL.DROP.Temporary.information_schema` MEDIUMTEXT COMMENT 'temporarka',
					`SQL.CREATE.Temporary.information_schema` MEDIUMTEXT COMMENT 'temporarka',
					`SQL.DROP.Temporary.TAGS` MEDIUMTEXT COMMENT 'temporarka',
					`SQL.CREATE.Temporary.TAGS` MEDIUMTEXT COMMENT 'temporarka',

					`SQLINIT` MEDIUMTEXT COMMENT 'WHERE',
					`SQLFINAL` MEDIUMTEXT COMMENT 'WHERE',
					
					`sect.COLUMNS` MEDIUMTEXT COMMENT 'SELECT',
					`sect.COLUMNS_AGG` MEDIUMTEXT COMMENT 'SELECT.AGG',
					`sect.FROM` MEDIUMTEXT COMMENT 'FROM',
					`sect.JOIN` MEDIUMTEXT COMMENT 'JOIN',
					`sect.WHERE` MEDIUMTEXT COMMENT 'WHERE',
					`sect.WHERE.S` MEDIUMTEXT COMMENT 'WHERE browsera',
					`sect.WHERE.S.ADD` MEDIUMTEXT COMMENT 'WHERE alternatywny browsera dodatkowy który jest usuwany przy refreshtime i ląduje w polu REC_OK',
					`sect.WHERE.P` MEDIUMTEXT COMMENT 'WHERE alternatywny filtrow',
					`sect.WHERE.V` MEDIUMTEXT COMMENT 'WHERE alternatywny aktualnego widoku',
					`sect.WHERE.MaxTime` MEDIUMTEXT COMMENT 'WHERE',
					`sect.WHERE.Key` MEDIUMTEXT COMMENT 'WHERE',
					`sect.HAVING` MEDIUMTEXT COMMENT 'HAVING',
					`sect.HAVING.P` MEDIUMTEXT COMMENT 'HAVING',
					`sect.HAVING.S` MEDIUMTEXT COMMENT 'HAVING',
					`sect.GROUP` MEDIUMTEXT COMMENT 'GROUP',
					`sect.GROUP.P` MEDIUMTEXT COMMENT 'GROUP',
					`sect.GROUP.S` MEDIUMTEXT COMMENT 'GROUP',
					`sect.ORDER` MEDIUMTEXT COMMENT 'GROUP',
					`sect.LIMIT` MEDIUMTEXT COMMENT 'LIMIT',
					`sect.WHERE.S.ADD.V.P` MEDIUMTEXT COMMENT 'Łączny WHERE zaw. dod. browsera, widok i filtry',

					`comment.COLUMNS` VARCHAR(100) DEFAULT 'Content',
					`comment.COLUMNS_AGG` VARCHAR(100) DEFAULT 'Agg. content',
					`comment.FROM` VARCHAR(100) DEFAULT 'FROM',
					`comment.JOIN` VARCHAR(100) DEFAULT 'JOIN',
					`comment.WHERE` VARCHAR(100) DEFAULT 'WHERE ...',
					`comment.WHERE.S` VARCHAR(100) DEFAULT 'WHERE staly browsera',
					`comment.WHERE.S.ADD` VARCHAR(100) DEFAULT 'WHERE alternatywny browsera dodatkowy',
					`comment.WHERE.P` MEDIUMTEXT COMMENT 'WHERE alternatywny filtrow',
					`comment.WHERE.V` VARCHAR(100) DEFAULT 'WHERE alternatywny aktualnego widoku',
					`comment.WHERE.Key` VARCHAR(100) DEFAULT 'WHERE dla refresh Key',
					`comment.WHERE.MaxTime` VARCHAR(100) DEFAULT 'WHERE dla refresh time',
					`comment.EXT1` VARCHAR(100) DEFAULT 'Pole REC_OK gdy tryb refresh key lub refresh time',
					`comment.HAVING` VARCHAR(100) DEFAULT 'HAVING',
					`comment.HAVING.P` VARCHAR(100) DEFAULT 'HAVING',
					`comment.HAVING.S` VARCHAR(100) DEFAULT 'HAVING',
					`comment.GROUP` VARCHAR(100) DEFAULT 'GROUP BY',
					`comment.GROUP.P` VARCHAR(100) DEFAULT 'GROUP BY',
					`comment.GROUP.S` VARCHAR(100) DEFAULT 'GROUP BY',
					`comment.ORDER` VARCHAR(100) DEFAULT 'ORDER',
					`comment.LIMIT` VARCHAR(100) DEFAULT 'LIMIT',
					
					`Is.WHERE.Refresh` BOOLEAN DEFAULT FALSE,
					
					`temptable.name` VARCHAR(250) NOT NULL DEFAULT '',
					`temptable.name.check` VARCHAR(250) NOT NULL DEFAULT '',
					`temptable.name.maxtime` VARCHAR(250) NOT NULL DEFAULT '',
					`temptable.name.key` VARCHAR(250) NOT NULL DEFAULT '',
					`temptable.name.information_schema` VARCHAR(250) NOT NULL DEFAULT '',
					`temptable.name.TAGS` VARCHAR(250) NOT NULL DEFAULT '',
					
					`Limit` MEDIUMTEXT COMMENT 'LIMIT wejsciowy',
				--	Pole Key
					`Key_FieldName` VARCHAR(250) NOT NULL DEFAULT '',
					`Key_FieldValue` VARCHAR(250) NOT NULL DEFAULT '',
				--	Pole Localtime 	
					`LocalTime_FieldName` VARCHAR(250) NOT NULL DEFAULT '',
					`LocalTime_FieldValue` VARCHAR(250) NOT NULL DEFAULT '',

					
					`_Param_DEFAULT_WHERE` VARCHAR(150) NOT NULL DEFAULT '',
					`_Param_A` VARCHAR(150) NOT NULL DEFAULT '',
					`_Param_B` VARCHAR(150) NOT NULL DEFAULT '',
					`_Param_C` VARCHAR(150) NOT NULL DEFAULT '',
					`_Param_D` VARCHAR(150) NOT NULL DEFAULT '',
					`_Param_E` VARCHAR(150) NOT NULL DEFAULT '',
					`Is_SQL` BOOLEAN DEFAULT FALSE,
					`Is_information_schema` BOOLEAN DEFAULT FALSE,
					`Have_Agg` BOOLEAN DEFAULT FALSE,
					PRIMARY KEY (`ID_SECT`)
				);
				
				
				DROP TEMPORARY TABLE IF EXISTS `t_browser.sql.statements`;
				CREATE TEMPORARY TABLE `t_browser.sql.statements` (
					`ID` VARCHAR(150) NOT NULL DEFAULT '' COMMENT 'Klucz glowny',
					`LP` VARCHAR(150) NOT NULL DEFAULT '' COMMENT '',
					`Id_browser` VARCHAR(38) NOT NULL DEFAULT '' COMMENT 'Klucz browsera',
					`Kind` VARCHAR(150) NOT NULL DEFAULT '' COMMENT 'Kind z sql',
					`Context` VARCHAR(150) NOT NULL DEFAULT 'select' COMMENT 'np. information_schema',
					`SQL.Init.Template` MEDIUMTEXT COMMENT '[select]....',
					`SQL.Exe` MEDIUMTEXT COMMENT 'Zwykly select / call',
					
					`_Param_DEFAULT_WHERE` VARCHAR(150) NOT NULL DEFAULT '',
					`_Param_A` VARCHAR(150) NOT NULL DEFAULT '',
					`_Param_B` VARCHAR(150) NOT NULL DEFAULT '',
					`_Param_C` VARCHAR(150) NOT NULL DEFAULT '',
					`_Param_D` VARCHAR(150) NOT NULL DEFAULT '',
					`_Param_E` VARCHAR(150) NOT NULL DEFAULT '',
					`Is_SQL` BOOLEAN DEFAULT FALSE,
					`Is_information_schema` BOOLEAN DEFAULT FALSE,
					PRIMARY KEY (`ID`)
				) DEFAULT CHARSET=UTF8
				;
				
			END IF;
							
							
			IF _MODE = 'SQL.FILL.`t_browser.sql.prepare`' THEN
					SET
						_Id_browser = _Key
					;
					UPDATE `t_browser.sql.prepare` t
					SET 
						-- t.Context = _Param_B,
						t.Is_SQL = TRUE, -- LOCATE('SELECT', SQLINIT) + LOCATE('CALL', SQLINIT) > 0,
						t.Is_information_schema = (Context = 'SELECT.information_schema'),
						t.SQLFINAL = t.SQLINIT
					;
					/*
					niepotrzebne
					UPDATE `t_browser.sql.prepare` t
					SET 
						_Param_DEFAULT_WHERE = IF(t.Is_information_schema, 'FALSE', t._Param_DEFAULT_WHERE)	--	dla Is_information_schema zawsze 'FALSE'
					;
					*/
				--	Pole Key
					UPDATE `t_browser.sql.prepare` t
					SET 
						t.`sect.WHERE.Key` = '', -- '\nAND TRUE\n',
						t.Key_FieldName = IFNULL(
							(
								SELECT
									c.sql_colref
								FROM `tx_sys_browsers_col` c
								WHERE
									c.IsKey
									AND NOT c.Deleted
								LIMIT 1
							)
						, '')
					;
				--	Pole Localtime 	
					UPDATE `t_browser.sql.prepare` t
					SET 
						t.`sect.WHERE.MaxTime` = '', -- '\nAND TRUE\n',
						t.LocalTime_FieldName = IFNULL(
							(
								SELECT
									c.sql_colref
								FROM `tx_sys_browsers_col` c
								WHERE
									c.IsLocalTime
									AND NOT c.Deleted
								LIMIT 1
							)
						, '')
					;
					
					
					
					
					set @.trace.XXXX = _Id_browser;
					DROP TEMPORARY TABLE IF EXISTS `tx_sys_browsers_sect`; 
					CREATE TEMPORARY TABLE `tx_sys_browsers_sect` 
						SELECT
							s.*,
							_VarInt(
								!(s.Kind LIKE '%inner%' OR s.Kind LIKE '%left%') 
								OR
								s.AlwaysIncluded
							) AS Included
						FROM `_sys_browsers_sect` s, `t_browser.sql.prepare` t
						WHERE
							s.Id_browser = _Id_browser
							AND NOT s.Deleted
							-- AND (s.Views = '' OR s.Views LIKE CONCAT('%', t.View, '%'))
							-- AND (s.Views = '' OR t.View = s.Views OR (t.View != '' AND LOCATE(t.View, s.Views) > 0))
							AND (s.Views = '' OR t.View = s.Views OR (t.View != '' AND s.Views LIKE CONCAT('%', t.View, '%')))
					;	
					DROP TEMPORARY TABLE IF EXISTS `tx_sys_browsers_sect_need`; 
					CREATE TEMPORARY TABLE `tx_sys_browsers_sect_need` (
					  `Source_sect` VARCHAR(38) NOT NULL DEFAULT '' COMMENT 'Klucz glowny',
					   PRIMARY KEY (`Source_sect`)
					)
					;
					set @.trace.X = 'FILL.main.SQL.3';
					INSERT IGNORE INTO `tx_sys_browsers_sect_need`
						SELECT
							n.Source_sect
						FROM `tx_sys_browsers_col` c, `_sys_browsers_sect_need` n, `_sys_browsers_sect` s, `t_browser.sql.prepare` t
						WHERE
							c.Included
							AND 
							n.GUID = c.def_c_GUID
							AND
							s.GUID = n.Source_sect
							AND
							NOT s.Deleted
							-- AND (s.Views = '' OR s.Views LIKE CONCAT('%', t.View, '%'))
							-- AND (s.Views = '' OR t.View = s.Views OR (t.View != '' AND LOCATE(t.View, s.Views) > 0))
							AND (s.Views = '' OR t.View = s.Views OR (t.View != '' AND s.Views LIKE CONCAT('%', t.View, '%')))
					;	
					UPDATE `tx_sys_browsers_sect` s
					SET
						s.Included = EXISTS(SELECT n.Source_sect FROM `tx_sys_browsers_sect_need` n WHERE s.GUID = n.Source_sect)
					WHERE
						(s.Kind LIKE '%inner%' OR s.Kind LIKE '%left%' OR s.Kind LIKE '%from%') 
						AND !s.Included
					;
					INSERT IGNORE INTO `tx_sys_browsers_sect_need`
						SELECT
							n.Source_sect
						FROM `tx_sys_browsers_sect` t, `_sys_browsers_sect_need` n, `_sys_browsers_sect` s
						WHERE
							t.Included
							AND 
							n.GUID = t.GUID
							AND
							s.GUID = n.Source_sect
							AND
							NOT s.Deleted
					;	
					set @.trace.X = 'FILL.main.SQL.7';
					UPDATE `tx_sys_browsers_sect` s
					SET
						s.Included = EXISTS(SELECT n.Source_sect FROM `tx_sys_browsers_sect_need` n WHERE s.GUID = n.Source_sect)
					WHERE
						(s.Kind LIKE '%inner%' OR s.Kind LIKE '%left%' OR s.Kind LIKE '%from%') 
						AND !s.Included
					;

				--	Inicjalnie	
					SET 
						@SYSTEM.Client.Session.GUID = IFNULL(@SYSTEM.Client.Session.GUID, '');
					SET
						@t.temptable.md5 = MD5(CONCAT(_Id_browser, @SYSTEM.Client.Session.GUID))
					;
					/*
					SET @t.temptable.name = CONCAT('`t_', @t.temptable.md5, '`');
					SET @t.temptable.name.check = CONCAT('`t_check_', @t.temptable.md5, '`');
					SET @t.temptable.name.maxtime = CONCAT('`t_maxtime_', @t.temptable.md5, '`');
					SET @t.temptable.name.key = CONCAT('`t_key_', @t.temptable.md5, '`');
					SET @t.temptable.name.information_schema = CONCAT('`t_information_schema_', @t.temptable.md5, '`');
					SET @t.temptable.name.TAGS = CONCAT('`t_TAGS_', @t.temptable.md5, '`');
					*/
					UPDATE `t_browser.sql.prepare` t
					SET
						t.`temptable.name` = CONCAT('t_', @t.temptable.md5, ''),
						t.`temptable.name.check` = CONCAT('t_check_', @t.temptable.md5, ''),
						t.`temptable.name.maxtime` = CONCAT('t_maxtime_', @t.temptable.md5, ''),
						t.`temptable.name.key` = CONCAT('t_key_', @t.temptable.md5, ''),
						t.`temptable.name.information_schema` = CONCAT('t_information_schema_', @t.temptable.md5, ''),
						t.`temptable.name.TAGS` = CONCAT('t_TAGS_', @t.temptable.md5, '')
					;

				
				
					
				--	SELECT
					UPDATE `t_browser.sql.prepare` t
					SET
						t.`sect.COLUMNS` = IFNULL(
						(
							SELECT 
								IFNULL(GROUP_CONCAT(c.sql_colref_AS ORDER BY c.LP SEPARATOR ",\n"), '') AS sql_colref_AS
							FROM `tx_sys_browsers_col` c
							WHERE
								c.Included
								AND (c.Views = '' OR t.View = c.Views OR (t.View != '' AND c.Views LIKE CONCAT('%', t.View, '%')))
						), '')
					WHERE
						t.Is_SQL
					;
				--	SELECT AGG
					UPDATE `t_browser.sql.prepare` t
					SET
						t.`sect.COLUMNS_AGG` = IFNULL(
						(
							SELECT 
								IFNULL(GROUP_CONCAT(c.sql_colref_AggFooter ORDER BY c.LP SEPARATOR ",\n"), '') AS sql_colref_AggFooter
							FROM `tx_sys_browsers_col` c
							WHERE
								c.Included
								AND
								c.AggFooterType != 'atNone'
								AND (c.Views = '' OR t.View = c.Views OR (t.View != '' AND c.Views LIKE CONCAT('%', t.View, '%')))
						), '')
					WHERE
						t.Is_SQL
					;
					UPDATE `t_browser.sql.prepare` t
					SET
						t.`Have_Agg` = t.`sect.COLUMNS_AGG` <> ''
					WHERE
						t.Is_SQL
					;
						
				--	FROM
					UPDATE `t_browser.sql.prepare` t
					SET
						t.`sect.FROM` = IFNULL(
						(
							SELECT 
								IFNULL(s.sql_Expr, '') AS C_SQLExpr
							FROM `_sys_browsers_sect` s
							WHERE
								s.Id_browser = _Id_browser
								AND s.Kind LIKE '%from%'
								AND (s.Views = '' OR t.View = s.Views OR (t.View != '' AND s.Views LIKE CONCAT('%', t.View, '%')))
							ORDER BY s.LP
							LIMIT 1
						), '')
					WHERE
						t.Is_SQL
					;
					
				--	JOINy
					UPDATE `t_browser.sql.prepare` t
					SET
						t.`sect.JOIN` = IFNULL(
						(
							SELECT 
								IFNULL(GROUP_CONCAT(s.sql_Expr ORDER BY s.LP SEPARATOR "\n"), '') AS C_SQLExpr
							FROM `tx_sys_browsers_sect` s
							WHERE
								s.Included
								AND (s.Kind LIKE '%left%') OR (s.Kind LIKE '%inner%')
								AND (s.Views = '' OR t.View = s.Views OR (t.View != '' AND s.Views LIKE CONCAT('%', t.View, '%')))
						), '')
					WHERE
						t.Is_SQL
					;


					
				--	WHERE browsera
					UPDATE `t_browser.sql.prepare` t
					SET
						t.`sect.WHERE.S` = 
						IFNULL(
						(
							SELECT 
								-- było IFNULL(GROUP_CONCAT(s.sql_Expr ORDER BY s.LP SEPARATOR "\nAND "), '\nTRUE') AS C_SQLExpr
								NULLIF(GROUP_CONCAT(s.sql_Expr ORDER BY s.LP SEPARATOR "\nAND "), '') AS C_SQLExpr
							FROM `_sys_browsers_sect` s
							WHERE
								s.Id_browser = t.Id_browser
								AND (s.Kind LIKE '%where%')
								AND s.Deleted = 0
								-- AND (s.Views = '' OR t.View = s.Views OR (t.View != '' AND s.Views LIKE CONCAT('%', t.View, '%')))
								AND (s.Views = '')	-- czyli zwykły WHERE browsera

						), '')
					WHERE
						t.Is_SQL
					;
				--	WHERE browsera dodatkowy który jest usuwany przy refreshtime i ląduje w polu REC_OK
					UPDATE `t_browser.sql.prepare` t
					SET
						t.`sect.WHERE.S.ADD` = 
						IFNULL(
						(
							SELECT 
								-- było IFNULL(GROUP_CONCAT(s.sql_Expr ORDER BY s.LP SEPARATOR "\nAND "), '\nTRUE') AS C_SQLExpr
								NULLIF(GROUP_CONCAT(s.sql_Expr ORDER BY s.LP SEPARATOR "\nAND "), '') AS C_SQLExpr
							FROM `_sys_browsers_sect` s
							WHERE
								s.Id_browser = t.Id_browser
								AND (s.Kind LIKE '%where%')
								AND s.Deleted = 0
								-- AND (s.Views = '' OR t.View = s.Views OR (t.View != '' AND s.Views LIKE CONCAT('%', t.View, '%')))
								AND (s.Views = 'ADD_WHERE')	-- czyli WHERE browsera dodatkowy który jest usuwany przy refreshtime i ląduje w polu REC_OK

						), '')
					WHERE
						t.Is_SQL
					;
				--	WHERE widoku
					UPDATE `t_browser.sql.prepare` t
					SET
						t.`sect.WHERE.V` = 
						IFNULL(
						(
							SELECT 
								-- było IFNULL(GROUP_CONCAT(s.sql_Expr ORDER BY s.LP SEPARATOR "\nAND "), '\nTRUE') AS C_SQLExpr
								NULLIF(GROUP_CONCAT(s.sql_Expr ORDER BY s.LP SEPARATOR "\nAND "), '') AS C_SQLExpr
							FROM `_sys_browsers_sect` s
							WHERE
								s.Id_browser = t.Id_browser
								AND (s.Kind LIKE '%where%')
								AND s.Deleted = 0
								-- AND (s.Views = '' OR t.View = '' OR s.Views LIKE CONCAT('%', t.View, '%'))
								-- AND (s.Views = '' OR t.View = s.Views OR (t.View != '' AND LOCATE(t.View, s.Views) > 0))
								AND (t.View = s.Views OR (t.View != '' AND s.Views LIKE CONCAT('%', t.View, '%')))

						), '')
					WHERE
						t.Is_SQL
					;
				--	WHERE filtrów
					UPDATE `t_browser.sql.prepare` t
					SET
						t.`sect.WHERE.P` = 
						IFNULL(
						(
							SELECT 
								-- było IFNULL(GROUP_CONCAT(f.Filter_FilterExpr ORDER BY f.LP SEPARATOR "\nAND "), '') AS C_SQLExpr
								NULLIF(GROUP_CONCAT(f.Filter_FilterExpr ORDER BY f.LP SEPARATOR "\nAND "), '') AS C_SQLExpr
							FROM `tx_sys_browsers_filters` f 
							WHERE
								f.Included
								AND f.Kind = 'WHERE' 
								AND f.Filter_Active
						), '')
					WHERE
						t.Is_SQL
					;
				--	Łączny WHERE zaw. dod. browsera, widok i filtry
					UPDATE `t_browser.sql.prepare` t
					SET
						t.`sect.WHERE.S.ADD.V.P` = NULLIF(
							CONCAT_WS('\nAND\n', 
							-- 	WHERE browsera dodatkowy który jest usuwany przy refreshtime i ląduje w polu REC_OK
								_SQL_FMT_Stat('', @.SQL.FS.WHERE.S.ADD, '', '', NULLIF(t.`sect.WHERE.S.ADD`, ''), 1, '', NULL),
								-- _ConcatSQLPreSeqPost(t.`comment.WHERE.S.ADD`, '', NULLIF(t.`sect.WHERE.S.ADD`, ''), '', 'TAB'), 	-- WHERE browsera dodatkowy który jest usuwany przy refreshtime i ląduje w polu REC_OK
							-- 	WHERE z widoku	
								_SQL_FMT_Stat('', @.SQL.FS.WHERE.V, '', '', NULLIF(t.`sect.WHERE.V`, ''), 1, '', NULL),
								-- _ConcatSQLPreSeqPost(t.`comment.WHERE.V`, '', NULLIF(t.`sect.WHERE.V`, ''), '', 'TAB'), 		-- WHERE z widoku
							-- 	WHERE z filtrów
								_SQL_FMT_Stat('', @.SQL.FS.WHERE.P, '', '', NULLIF(t.`sect.WHERE.P`, ''), 1, '', NULL)
								-- _ConcatSQLPreSeqPost(t.`comment.WHERE.P`, '', NULLIF(t.`sect.WHERE.P`, ''), '', 'TAB')		-- WHERE z filtrów
							), 
							/*
							CONCAT_WS('\nAND\n', 
							-- 	WHERE browsera dodatkowy który jest usuwany przy refreshtime i ląduje w polu REC_OK
								_ConcatSQLPreSeqPost(t.`comment.WHERE.S.ADD`, '', NULLIF(t.`sect.WHERE.S.ADD`, ''), '', 'TAB'), 	-- WHERE browsera dodatkowy który jest usuwany przy refreshtime i ląduje w polu REC_OK
							-- 	WHERE z widoku	
								_ConcatSQLPreSeqPost(t.`comment.WHERE.V`, '', NULLIF(t.`sect.WHERE.V`, ''), '', 'TAB'), 		-- WHERE z widoku
							-- 	WHERE z filtrów
								_ConcatSQLPreSeqPost(t.`comment.WHERE.P`, '', NULLIF(t.`sect.WHERE.P`, ''), '', 'TAB')		-- WHERE z filtrów
							), 
							*/
							''
						)
					WHERE
						t.Is_SQL
					;
			--	Pole Key
					UPDATE `t_browser.sql.prepare` t
					SET
						t.`sect.WHERE.Key` = 
						IFNULL(
							-- CONCAT('\nAND (', t.Key_FieldName, ' = ', QUOTE(t.Key_FieldValue), ')\n')
							CONCAT('(', t.Key_FieldName, ' = ', QUOTE(t.Key_FieldValue), ')')
						, '')
					WHERE
						t.Is_SQL
						AND
						t.Key_FieldName <> ''
						AND
						t.Key_FieldValue <> ''
					;
			--	Pole Localtime 	
					UPDATE `t_browser.sql.prepare` t
					SET
						t.`sect.WHERE.MaxTime` = 
						IFNULL(
							-- CONCAT('\nAND (', t.LocalTime_FieldName, ' >= ', QUOTE(t.LocalTime_FieldValue), ')\n')
							CONCAT('(', t.LocalTime_FieldName, ' >= ', QUOTE(t.LocalTime_FieldValue), ')')
						, '')
					WHERE
						t.Is_SQL
						AND
						t.LocalTime_FieldName <> ''
						AND
						t.LocalTime_FieldValue <> ''
					;
					SET @.trace.X.MaxTime = ROW_COUNT() + 100;
					SET @.trace.X.MaxTime = (select CONCAT(@.trace.X.MaxTime, ' - (', t.LocalTime_FieldName, ' >= ', QUOTE(t.LocalTime_FieldValue), ')') from `t_browser.sql.prepare` t);
					
					UPDATE `t_browser.sql.prepare` t
					SET
						t.`Is.WHERE.Refresh` = (t.`sect.WHERE.key` != '' OR t.`sect.WHERE.MaxTime` != '')
					WHERE
						t.Is_SQL
					;
					/*
					bylo ...
					UPDATE `t_browser.sql.prepare` t
					SET
						t.`sect.WHERE` = 
							IF(t.Context IN ('select', ''),
								_ConcatSTR2(t.`WHERE.S`, t.`WHERE.P`, "\nAND "),
								IF(t.Context IN ('maxtime', 'key', 'information_schema'),
									_ConcatSTR2(t.`WHERE.S`, t._Param_DEFAULT_WHERE, "\nAND "),
									t.`WHERE`
								)
							)
					WHERE
						t.Is_SQL
					;
					... jest */
					UPDATE `t_browser.sql.prepare` t
					SET
						t.`sect.WHERE` = 
							-- _ConcatSTR2(t.`sect.WHERE.S`, t.`sect.WHERE.P`, "\nAND ")
							CONCAT_WS('\nAND\n', 
							-- 	WHERE browsera	
								-- CONCAT('/*** WHERE staly browsera  ***/\n', NULLIF(t.`sect.WHERE.S`, '')), 				-- WHERE browsera
								-- _ConcatSQLPreSeqPost(t.`comment.WHERE.S`, '', NULLIF(t.`sect.WHERE.S`, ''), '', 'TAB'),		
								_SQL_FMT_Stat('', @.SQL.FS.WHERE.S, '', '', NULLIF(t.`sect.WHERE.S`, ''), 1, '', NULL),
							--	UWAGA gdy mamy select z Key lub MaxTime to nie uzywamy filtrów czyli nie dodajemu tutaj np t.`sect.WHERE.P`
								IF(t.`Is.WHERE.Refresh`,
									IF(t.`sect.WHERE.key` != '',
									--	WHERE dla refresh key
										_SQL_FMT_Stat('', @.SQL.FS.WHERE.Key, '', '', NULLIF(t.`sect.WHERE.key`, ''), 1, '', NULL),
									--	WHERE dla refresh time
										_SQL_FMT_Stat('', @.SQL.FS.WHERE.MaxTime, '', '', NULLIF(t.`sect.WHERE.MaxTime`, ''), 1, '', NULL)
									),
								--	Łączny WHERE zaw. dod. browsera, widok i filtry
									_SQL_FMT_Stat('', @.SQL.FS.Empty, '', '', NULLIF(t.`sect.WHERE.S.ADD.V.P`, ''), 0, '', NULL)
								),
								'TRUE',
								NULL
							)
					WHERE
						t.Is_SQL
					;
					
				--	HAVING
					UPDATE `t_browser.sql.prepare` t
					SET
						t.`sect.HAVING.S` = (
							SELECT 
								IFNULL(GROUP_CONCAT(s.sql_Expr ORDER BY s.LP SEPARATOR " AND "), '') AS C_SQLExpr
							FROM `_sys_browsers_sect` s
							WHERE
								s.Id_browser = t.Id_browser
								AND (s.Kind LIKE '%having%')
								AND s.Deleted = 0
						)
					WHERE
						t.Is_SQL
					;
					UPDATE `t_browser.sql.prepare` t
					SET
						t.`sect.HAVING.P` = (
							SELECT 
								IFNULL(GROUP_CONCAT(f.Filter_FilterExpr ORDER BY f.LP SEPARATOR " AND "), '') AS C_SQLExpr
							FROM `tx_sys_browsers_filters` f 
							WHERE
								f.Included
								AND f.Kind = 'HAVING' 
								AND f.Filter_Active
						)
					WHERE
						t.Is_SQL
					;
					UPDATE `t_browser.sql.prepare` t
					SET
						t.`sect.HAVING` = 
							CONCAT_WS(' AND ', NULLIF(t.`sect.HAVING.S`, ''), NULLIF(t.`sect.HAVING.P`, '')) 
							--	_ConcatSTR2(t.`sect.HAVING.S`, t.`sect.HAVING.P`, " AND ")
					WHERE
						t.Is_SQL
					;
					/****
					TO jest uzywane??? WYWAL!!!!
					*/
					UPDATE `t_browser.sql.prepare` t
					SET
						t.SQLFINAL = 
							REPLACE(REPLACE(t.SQLFINAL, 
								"[WHERE]", _ConcatSQLPreSeqPost(t.`comment.WHERE`, '', t.`Sect.WHERE`, '', 'TAB')), 
								"[HAVING]", IFNULL(_ConcatSQLPreSeq(t.`comment.WHERE`, NULLIF(t.`Sect.HAVING`, ''), 'TAB'), '/*** No HAVING ***/')
								-- "[HAVING]", IF(t.`sect.HAVING` != '', CONCAT("\nHAVING \n", t.`sect.HAVING`), '')
							)
					WHERE
						t.Is_SQL
					;
				-- SET @sql.text.C = @sql.text.template;
				
				
				--	GROUP.S
					UPDATE `t_browser.sql.prepare` t
					SET
						t.`sect.GROUP.S` = IFNULL(
						(
							SELECT 
								IFNULL(GROUP_CONCAT(s.sql_Expr ORDER BY s.LP SEPARATOR ", "), '') AS C_SQLExpr
							FROM `_sys_browsers_sect` s
							WHERE
								s.Id_browser = t.Id_browser
								AND (s.Kind LIKE '%GROUP%')
						), '')
					WHERE
						t.Is_SQL
					;
						
				--	GROUP.P
					UPDATE `t_browser.sql.prepare` t
					SET
						t.`sect.GROUP.P` = IFNULL(
						(
							SELECT 
								IFNULL(GROUP_CONCAT(IF(IFNULL(c.GROUP_BY_Expr, '') != '', c.GROUP_BY_Expr, IF(IFNULL(c.col_NameAS, '') != '', c.col_NameAS, IF(IFNULL(c.col_Name, '') != '', c.col_Name, ''))) ORDER BY c.LP SEPARATOR ", "), '') AS C_SQLExpr
							FROM `tx_sys_browsers_col` c
							WHERE
								c.Included
								AND c.GROUP_BY_Ord > -1
						), '')
					WHERE
						t.Is_SQL
					;
				--	GROUP
					UPDATE `t_browser.sql.prepare` t
					SET
						t.`sect.GROUP` = IFNULL(
						(
							_ConcatSTR2(t.`sect.GROUP.S`, t.`sect.GROUP.P`, ", ")
						), '')
					WHERE
						t.Is_SQL
					;
					
				--	ORDER
					UPDATE `t_browser.sql.prepare` t
					SET
						t.`sect.ORDER` = IFNULL(
						(
							SELECT 
								IFNULL(GROUP_CONCAT(s.sql_Expr ORDER BY s.LP SEPARATOR ", "), '') AS C_SQLExpr
							FROM `_sys_browsers_sect` s
							WHERE
								s.Id_browser = t.Id_browser
								AND (s.Kind LIKE '%ORDER%')
						), '')
					WHERE
						t.Is_SQL
					;
				--	LIMIT
					UPDATE `t_browser.sql.prepare` t
					SET
						t.`sect.LIMIT` = NULLIF(
						(
							SELECT 
								IFNULL(s.sql_Expr, '') AS C_SQLExpr
							FROM `_sys_browsers_sect` s
							WHERE
								s.Id_browser = t.Id_browser
								AND s.Kind LIKE '%limit%'
							ORDER BY s.LP
							LIMIT 1
						), '')
					WHERE
						t.Is_SQL
					;
				--	LIMIT cz.2 gdy NULL - nie było limitów w sekscjach
					UPDATE `t_browser.sql.prepare` t
					SET
						t.`sect.LIMIT` = 
							CONCAT('LIMIT ', (TRIM(NULLIF(REPLACE(UCASE(NULLIF(t.Limit, '')), 'LIMIT', ''), ''))))
					WHERE
						t.Is_SQL
						AND t.`sect.LIMIT` IS NULL
					;
					
					
			END IF;
							

	IF _MODE = 'SQL.INIT' THEN
		-- CALL _sys_watch_time_Tools('start', 'SQL.INIT', '-', '', '', '');
	
		SET
			_Id_browser = _Key,
			_Context = IF(IFNULL(_Key2, '') = '', 'select', _Key2),
		-- 	Context
		--	"SELECT", "SELECT.TEMP", "SELECT.AGG", "SELECT.KEY", "SELECT.MAXTIME", "SELECT.TAGS", "SELECT.information_schema"
			_Limit = _Param_A, 
			_Key = _Param_B, 
			_MaxTime = _Param_C
		;
		IF IFNULL(@SYSTEM.Client.Session.log_USER_GUID, '') = '' THEN
			CALL _sys_db_logons_rec_tools('GET.@SYSTEM.Client.Session.log_USER_GUID', @SYSTEM.Client.Session.GUID, 0, '', '', '', '', '');
		END IF;
		-- SET _User = @SYSTEM.Client.Session.log_USER_GUID;
		
		set @_Id_browser = _Id_browser;
		set @szloch = 'aaa';

			SELECT
				n.Params,
				n.LimitRec,
				TRUE,
				EXISTS(SELECT g.GrupaGUID FROM `grupy_osob` g WHERE g.GrupaGUID = IF(IFNULL(n.UgrpGuid, '') = '', 'ALL', n.UgrpGuid) AND g.OsobaGUID = @SYSTEM.Client.Session.GUID) AS UgrpGuid_OK
			INTO
				@.sql.n.Params,
				@.sql.n.LimitRec,
				@.sql.n.Exists,
				@.sql.n.UgrpGuid_OK
			FROM `_sys_browsers_n` n
			WHERE
				n.ID = _Id_browser
			;
			IF NOT @.sql.n.Exists THEN	
				SET @.sql.Err = 'Nie istnieje taki browser!';
			ELSEIF NOT @.sql.n.UgrpGuid_OK THEN
				SET @.sql.Err = 'Nie ma uprawnien do takiego browsera!';
			END IF;
		
-- CALL _sys_watch_time_Tools('start', 'SQL.INIT', 'SQL.CREATE.t_browser.sql.prepare', '', '', '');
			CALL _SQL_Exe('SQL.CREATE.t_browser.sql.prepare', '', '', '', @SQL, '', '', '', '', '');
-- CALL _sys_watch_time_Tools('stop', 'SQL.INIT', 'SQL.CREATE.t_browser.sql.prepare', '', '', '');
		--	WSTAW	
-- CALL _sys_watch_time_Tools('start', 'SQL.INIT', '2', '', '', '');
			REPLACE `t_browser.sql.prepare`
			-- (ID_SECT, Kind, `Context`, _Id_browser, SQLINIT, _Param_A, _Param_B, _Param_C, _Param_D, _Param_E)
			(ID_SECT, `Context`, Id_browser, `View`, SQLINIT, `Limit`)
				SELECT 
					_ID_SQL, _Context, _Id_browser, _Key3, _SQL, IF(_Limit != '', _Limit, @.sql.n.LimitRec)
			;
			SET @.trace.X.2 = ROW_COUNT();
			
			UPDATE `t_browser.sql.prepare` t
			SET 
				-- t.Context = _Context,
				-- t.Is_SQL = LOCATE('SELECT', SQLINIT) + LOCATE('CALL', SQLINIT) > 0,
				-- t.Is_information_schema = (_Context = 'SELECT.information_schema'),
				-- t.SQLFINAL = t.SQLINIT,
				-- t.Limit = IF(_Param_A != '', _Param_A, t.Limit),
				t.Key_FieldValue = _Key, -- _Param_B,
				t.LocalTime_FieldValue = _MaxTime, -- _Param_C,
				t.`Have_Agg` = (@.t.Have_Agg := t.`Have_Agg`)
			;

			IF _Context = 'information_schema' THEN	--	information_schema
				CALL sys_browsers_tools('sqltext.init.by.system', _Id_browser, '', '', '', '', '', '', '');
			ELSE
				CALL sys_browsers_tools('sqltext.init.by.profil', _Id_browser, '', '', '', '', '', '', '');
			END IF;
			--	do @.Prf.GUID wpisywany jest GUID profilu
-- CALL _sys_watch_time_Tools('stop', 'SQL.INIT', '2', '', '', '');
			
-- CALL _sys_watch_time_Tools('start', 'SQL.INIT', '3', '', '', '');
-- -- CALL _sys_watch_time_Tools('start', 'SQL.INIT', '3.0', '', '', '');
			CALL _SQL_Exe('SQL.FILL.`t_browser.sql.prepare`', _Id_browser, '', '', @SQL, '', '', '', '', '');			
-- -- CALL _sys_watch_time_Tools('stop', 'SQL.INIT', '3.0', '', '', '');
			
-- -- CALL _sys_watch_time_Tools('start', 'SQL.INIT', '3.1', '', '', '');
-- CALL _sys_watch_time_Tools('start', 'SQL.INIT', 'default.PARAMS', '', '', '');
set @_Id_browser.X = _Id_browser, @_PrfGUID_p.X = _PrfGUID_p, @_All_PrfGUID.X = @_All_PrfGUID;
					--	Koniecznie ustaw @_All_PrfGUID na null bo moze byc tam cos wypełnione
						SET @_All_PrfGUID = NULL;
						CALL _sys_usr_profile_utilities('get.profil.default.PARAMS', _Id_browser, _PrfGUID_p, @_All_PrfGUID, @SYSTEM.Client.Session.log_USER_GUID, '', '', '', '', '');
-- CALL _sys_watch_time_Tools('stop', 'SQL.INIT', 'default.PARAMS', '', '', '');
-- -- CALL _sys_watch_time_Tools('stop', 'SQL.INIT', '3.1', '', '', '');
						--	przygotu TempTable parametrow dla _PrfGUID_p
-- -- CALL _sys_watch_time_Tools('start', 'SQL.INIT', '3.2', '', '', '');
						CALL _PrepareSQLText_with_HashParams('init', @We, '', @_f_Value_Down, _PrfGUID_p, @_Result, @_ResultMsg, '', '');
-- -- CALL _sys_watch_time_Tools('stop', 'SQL.INIT', '3.2', '', '', '');
						--	Inicjalne
-- CALL _sys_watch_time_Tools('start', 'SQL.INIT', '3.3', '', '', '');
						CALL _PrepareSQLText_with_HashParams('Execute.Before.After.execute.sql.INIT', @nothing, @nothing, @nothing, _Id_browser, @.sql.Err, @.sql.INFO, '', '');
-- CALL _sys_watch_time_Tools('stop', 'SQL.INIT', '3.3', '', '', '');
						--	Finalne przenies gdzie indziej TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-- CALL _sys_watch_time_Tools('start', 'SQL.INIT', '3.4', '', '', '');
						CALL _PrepareSQLText_with_HashParams('Execute.Before.After.execute.sql.FINAL', @nothing, @nothing, @nothing, _Id_browser, @.sql.Err, @.sql.INFO, '', '');
-- CALL _sys_watch_time_Tools('stop', 'SQL.INIT', '3.4', '', '', '');
-- CALL _sys_watch_time_Tools('stop', 'SQL.INIT', '3', '', '', '');
			
			
		-- CALL _sys_watch_time_Tools('stop', 'SQL.INIT', '-', '', '', '');
	END IF;


	IF _MODE = 'SQL.PREPARE.SQL' THEN
		SET
			_Id_browser = _Key,
			_Context = IF(IFNULL(_Key2, '') = '', 'select', _Key2)
		-- 	Context
		--	"SELECT", "SELECT.TEMP", "SELECT.AGG", "SELECT.KEY", "SELECT.MAXTIME", "SELECT.TAGS", "SELECT.information_schema"
		;
		set @._Param_C = _Param_C;
		UPDATE `t_browser.sql.prepare` t
		SET 
			t.Context = _Context,
			t.Is_SQL = LOCATE('SELECT', SQLINIT) + LOCATE('CALL', SQLINIT) > 0,
			t.Is_information_schema = (_Context = 'SELECT.information_schema'),
			t.SQLFINAL = t.SQLINIT,
			t.Limit = IF(_Param_A != '', _Param_A, t.Limit),
			-- t.Key_FieldValue = _Param_B,
			-- t.LocalTime_FieldValue = _Param_C,
			t.`Have_Agg` = (@.t.Have_Agg := t.`Have_Agg`)
		;
		TRUNCATE `t_browser.sql.statements`;
		
		-- IF _Context = "SELECT" AND  THEN
		-- END IF;
		
		IF _Context = "SELECT" AND NOT @.t.Have_Agg THEN
		--	SELECT ALE!!!! jest to browser bez agrergatow !!!
			SET
				_SQL = ""
			;
			-- CALL _SQL_Exe("INSERT.into.statements", 'Init.DROP', '1', '', _SQL, '', '', '', '', '');
			-- CALL _SQL_Exe("INSERT.into.statements", 'Init.CREATE', '2', '', _SQL, '', '', '', '', '');
			SET
				_SQL = 
				-- "SELECT[SQL_CALC_FOUND_ROWS]\n[COLUMNS]\n-- EXT1\n-- EXT2\nFROM [FROM]\n[JOIN]\nWHERE\n[WHERE][WHERE.MaxTime][GROUP][HAVING][ORDER][LIMIT]\n;"
				"SELECT[SQL_CALC_FOUND_ROWS]\n[COLUMNS]\n-- EXT1\n-- EXT2\nFROM [FROM]\n[JOIN]\nWHERE\n[WHERE][GROUP][HAVING][ORDER][LIMIT]\n;"
			;
			CALL _SQL_Exe("INSERT.into.statements", 'SELECT', '1', '', _SQL, '', '', '', '', '');
		END IF;

		
		IF _Context = "SELECT.temp" OR (_Context = "SELECT"  AND @.t.Have_Agg ) THEN
		--	SELECT z temporarki lub zwykly ale jest to browser ktory ma agrergaty !!!  a wtedy zawsze z temporarki
			SET
				_SQL = "DROP TEMPORARY TABLE IF EXISTS `<temptable.name>`\n;"
			;
			CALL _SQL_Exe("INSERT.into.statements", 'Init.DROP', '1', '', _SQL, '', '', '', '', '');
			SET
				_SQL = "CREATE TEMPORARY TABLE IF NOT EXISTS `<temptable.name>`\nSELECT[SQL_CALC_FOUND_ROWS]\n[COLUMNS]\n-- EXT1\n-- EXT2\nFROM [FROM]\n[JOIN]\nWHERE\n[WHERE][GROUP][HAVING][ORDER][LIMIT]\n;"
			;
			CALL _SQL_Exe("INSERT.into.statements", 'Init.CREATE', '2', '', _SQL, '', '', '', '', '');
			SET
				_SQL = 
				"SELECT t.* FROM `<temptable.name>` t\n;"
			;
			CALL _SQL_Exe("INSERT.into.statements", 'SELECT', '3', '', _SQL, '', '', '', '', '');
			SET
				-- _SQL = "DROP TEMPORARY TABLE IF EXISTS `<temptable.name>`\n;"
				_SQL = "SET @A = 'a';"
			;
			CALL _SQL_Exe("INSERT.into.statements", 'Final.DROP', '4', '', _SQL, '', '', '', '', '');
			
		END IF;

		IF _Context = "SELECT.AGG" THEN
			
			SET
				_SQL = 
				"SELECT\n[COLUMNS.AGG]\nFROM `<temptable.name>` t\n;"
			;
			CALL _SQL_Exe("INSERT.into.statements", 'SELECT', '3', '', _SQL, '', '', '', '', '');
			SET
				-- _SQL = "DROP TEMPORARY TABLE IF EXISTS `<temptable.name>`\n;"
				_SQL = "SET @A = 'a';"
			;
		END IF;
		
		CALL _SQL_Exe("Fill.statements", 'SELECT', '1', '', _SQL, '', '', '', '', '');
		
	END IF;



					IF _MODE  = "INSERT.into.statements" THEN
						INSERT IGNORE INTO `t_browser.sql.statements`
						(ID, LP, Id_browser, Context, Kind, `SQL.Init.Template`, Is_information_schema)
							SELECT
								_Key AS ID, 
								_Key2 AS LP, 
								t.Id_browser, 
								t.Context AS Context,
								'' AS Kind,
								_SQL AS `SQL.Init.Template`,
								t.Is_information_schema AS Is_information_schema
							FROM `t_browser.sql.prepare` t
							WHERE
								TRUE
						;
					END IF;
					
					
					IF _MODE  = "Fill.statements" THEN
					
					/*
						[COLUMNS] 		kolumny
						[COLUMNS.AGG] 	kolumny agregacyjne
						[FROM]
						[JOIN]
						[WHERE]			concat where.S. i where.f
						[WHERE.key]		concat where.S. i where.f i where.key
						[WHERE.MaxTime]	concat where.S. i where.f i WHERE.MaxTime
						[GROUP]
						[HAVING]
						[ORDER]
						[LIMIT]
					*/
						UPDATE `t_browser.sql.statements` s, `t_browser.sql.prepare` t
						SET
							s.`SQL.EXE` = 
								REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(s.`SQL.Init.Template`, 
									"[SQL_CALC_FOUND_ROWS]", 
										IF(s.Context IN ('SELECT.Key', 'SELECT.MaxTime'),
											'\nSQL_CALC_FOUND_ROWS',
											''
										)
									),
									"[COLUMNS]", 
										t.`sect.COLUMNS`
									),
									"[COLUMNS.AGG]", 
										t.`sect.COLUMNS_AGG`
									),
									"\n-- EXT1", 
									-- 	Pole REC_OK gdy tryb refresh key lub refresh time
										_SQL_FMT_Stat('', @.SQL.FS.Ext1, '', '', 
											IFNULL(
												IF(t.`Is.WHERE.Refresh`, 
													t.`sect.WHERE.S.ADD.V.P`, 
													NULL
												),
												'TRUE'
											),
											2, '', ''
										)
									),
									"FROM [FROM]", "[FROM]"),
									"[FROM]", 
										-- t.`sect.FROM`
										_SQL_FMT_Stat('', @.SQL.FS.FROM, 'WHERE', '', t.`sect.FROM`, 0, '', '')
									),
									"[JOIN]", 
										t.`sect.JOIN`
									),
									"WHERE\n[WHERE]", 
										'[WHERE]'
									),
									"[WHERE]", 
										-- t.`sect.WHERE`
										_SQL_FMT_Stat('', @.SQL.FS.WHERE, 'WHERE', '', t.`sect.WHERE`, 1, '', '')
									),
									"[GROUP]", 
										-- IF(t.`sect.GROUP` != '', CONCAT("\nGROUP BY ", t.`sect.GROUP`), '')
										_SQL_FMT_Stat('', @.SQL.FS.GROUP, 'GROUP BY', '', t.`sect.GROUP`, 2, '', '')
									),
									"[HAVING]", 
										-- IF(t.`sect.HAVING` != '', CONCAT("\nHAVING \n", t.`sect.HAVING`), '')
										_SQL_FMT_Stat('', @.SQL.FS.HAVING, 'HAVING', '', t.`sect.HAVING`, 2, '', '')
									),
									"[ORDER]", 
										-- IF(t.`sect.ORDER` != '', CONCAT("\nORDER BY ", t.`sect.ORDER`), '')
										_SQL_FMT_Stat('', @.SQL.FS.ORDER, 'ORDER BY', '', t.`sect.ORDER`, 2, '', '')
									),
									"[LIMIT]", 
										_SQL_FMT_Stat('', @.SQL.FS.LIMIT, '', '', t.`sect.LIMIT`, 0, '', '')
										/*
										IF(t.Context IN ('select', 'SELECT.temp', ''),
											UPPER(
												IF(t.`sect.LIMIT` != '' AND t.`sect.LIMIT` != 0, 
													t.`sect.LIMIT`,
													IF(Locate('Limit', t.Limit) > 0, 
														CONCAT('\n', t.Limit), 
														IF(t.Limit != '' AND t.Limit != 0, 
															CONCAT('\nLIMIT ', t.Limit), 
															''
														)
													)
												)
											),
											''
										)
										*/
									)
						;
						
					/*
						ponadto nazwy tabel
						<temptable.name>
						<temptable.name.check>
						<temptable.name.key>
						<temptable.name.maxtime>
						<temptable.name.information_schema>
						<temptable.name.tags>
						SET @t.temptable.name = CONCAT('`t_', @t.temptable.md5, '`');
						SET @t.temptable.name.check = CONCAT('`t_check_', @t.temptable.md5, '`');
						SET @t.temptable.name.maxtime = CONCAT('`t_maxtime_', @t.temptable.md5, '`');
						SET @t.temptable.name.key = CONCAT('`t_key_', @t.temptable.md5, '`');
						SET @t.temptable.name.information_schema = CONCAT('`t_information_schema_', @t.temptable.md5, '`');
						SET @t.temptable.name.TAGS = CONCAT('`t_TAGS_', @t.temptable.md5, '`');
					*/
						UPDATE `t_browser.sql.statements` s, `t_browser.sql.prepare` t
						SET
							s.`SQL.EXE` = 
								REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(s.`SQL.EXE`, 
									"<temptable.name>", t.`temptable.name`),
									"<temptable.name.check>", t.`temptable.name.check`),
									"<temptable.name.key>", t.`temptable.name.key`),
									"<temptable.name.maxtime>", t.`temptable.name.maxtime`),
									"<temptable.name.information_schema>", t.`temptable.name.information_schema`),
									"<temptable.name.tags>", t.`temptable.name.TAGS`)
						;

					/*
						UPDATE `t_browser.sql.prepare` t
						SET
							t.`SQL.Body.Agg` = 
								REPLACE(t.`SQL.Body`,
									"[SELECT]", t.SELECT.Agg),
							t.`SQL.Body` = 
								REPLACE(t.`SQL.Body`,
									"[SELECT]", t.SELECT)
						;


									
						
					--	SELECT  LIMIT, WHERE etc
						UPDATE `t_browser.sql.prepare` t
						SET
							t.`SQL.Body.Agg` =
								REPLACE(REPLACE(REPLACE(REPLACE(t.`SQL.Body.Agg`, 
									"[WHERE]", _ConcatSTR2(t.`WHERE`, t.`WHERE.MaxTime`, "\nAND ")),
									"-- EXT1", CONCAT(', (', IF(t.`WHERE.P` != '', t.`WHERE.P`, 'TRUE'),') AS REC_OK ')),
									"[LIMIT]", ''),
									"[SQL_CALC_FOUND_ROWS]", '\nSQL_CALC_FOUND_ROWS'),
									
							t.`SQL.Body.MaxTime` =
								REPLACE(REPLACE(REPLACE(REPLACE(t.`SQL.Body`, 
									"[WHERE]", _ConcatSTR2(t.`WHERE`, t.`WHERE.MaxTime`, "\nAND ")),
									"-- EXT1", CONCAT(', (', IF(t.`WHERE.P` != '', t.`WHERE.P`, 'TRUE'),') AS REC_OK ')),
									"[LIMIT]", ''),
									"[SQL_CALC_FOUND_ROWS]", '\nSQL_CALC_FOUND_ROWS'),
									
							t.`SQL.Body.Key` =
								REPLACE(REPLACE(REPLACE(REPLACE(t.`SQL.Body`, 
									"[WHERE]", _ConcatSTR2(t.`WHERE`, t.`WHERE.Key`, "\nAND ")),
									"-- EXT1", CONCAT(', (', IF(t.`WHERE.P` != '', t.`WHERE.P`, 'TRUE'),') AS REC_OK ')),
									"[LIMIT]", ''),
									"[SQL_CALC_FOUND_ROWS]", '\nSQL_CALC_FOUND_ROWS'),
									
							t.`SQL.Body.Schema` =
								REPLACE(REPLACE(REPLACE(t.`SQL.Body`, 
									"[WHERE]", 'FALSE'),
									"[LIMIT]", ''),
									"[SQL_CALC_FOUND_ROWS]", ''),

							t.`SQL.Body` = 
								REPLACE(REPLACE(REPLACE(t.`SQL.Body`, 
									"[WHERE]", t.WHERE),
									"[LIMIT]", IF(t.LIMIT <> '', CONCAT('\n', t.LIMIT), '')),
									"[SQL_CALC_FOUND_ROWS]", '')
						WHERE
							t.Is_SQL
						;
						
						
						UPDATE `t_browser.sql.prepare` t
						SET
							t.`SQL.Exe` = t.`SQL.Body`,
							
							t.`SQL.Exe.Temporary` = 
								REPLACE('SELECT * FROM `#temptable.name#`;',
									'#temptable.name#', t.`temptable.name`),
									
							t.`SQL.DROP.Temporary` = 
								REPLACE('DROP TEMPORARY TABLE IF EXISTS `#temptable.name#`;',
									'#temptable.name#', t.`temptable.name`),
							t.`SQL.CREATE.Temporary` = 
								REPLACE(REPLACE('CREATE TEMPORARY TABLE `#temptable.name#` \n#SQL.Body#',
									'#temptable.name#', t.`temptable.name`),
									'#SQL.Body#', t.`SQL.Body`),
									
							t.`SQL.DROP.Temporary.Check` = 
								REPLACE('DROP TEMPORARY TABLE IF EXISTS `#temptable.name#`;',
									'#temptable.name#', t.`temptable.name.check`),
							t.`SQL.CREATE.Temporary.Check` = 
								REPLACE(REPLACE('CREATE TEMPORARY TABLE `#temptable.name#` \n#SQL.Body#',
									'#temptable.name#', t.`temptable.name.check`),
									'#SQL.Body#', t.`SQL.Body`),
									
							t.`SQL.DROP.Temporary.maxtime` = 
								REPLACE('DROP TEMPORARY TABLE IF EXISTS `#temptable.name#`;',
									'#temptable.name#', t.`temptable.name.maxtime`),
							t.`SQL.CREATE.Temporary.maxtime` = 
								REPLACE(REPLACE('CREATE TEMPORARY TABLE `#temptable.name#` \n#SQL.Body#',
									'#temptable.name#', t.`temptable.name.maxtime`),
									'#SQL.Body#', t.`SQL.Body`),
									
							t.`SQL.DROP.Temporary.key` = 
								REPLACE('DROP TEMPORARY TABLE IF EXISTS `#temptable.name#`;',
									'#temptable.name#', t.`temptable.name.key`),
							t.`SQL.CREATE.Temporary.key` = 
								REPLACE(REPLACE('CREATE TEMPORARY TABLE `#temptable.name#` \n#SQL.Body#',
									'#temptable.name#', t.`temptable.name.key`),
									'#SQL.Body#', t.`SQL.Body`),
									
							t.`SQL.DROP.Temporary.information_schema` = 
								REPLACE('DROP TEMPORARY TABLE IF EXISTS `#temptable.name#`;',
									'#temptable.name#', t.`temptable.name.information_schema`),
							t.`SQL.CREATE.Temporary.information_schema` = 
								REPLACE(REPLACE('CREATE TEMPORARY TABLE `#temptable.name#` \n#SQL.Body#',
									'#temptable.name#', t.`temptable.name.information_schema`),
									'#SQL.Body#', t.`SQL.Body`),
									
							t.`SQL.DROP.Temporary.TAGS` = 
								REPLACE('DROP TEMPORARY TABLE IF EXISTS `#temptable.name#`;',
									'#temptable.name#', t.`temptable.name.TAGS`),
							t.`SQL.CREATE.Temporary.TAGS` = 
								REPLACE(REPLACE('CREATE TEMPORARY TABLE `#temptable.name#` \n#SQL.Body#',
									'#temptable.name#', t.`temptable.name.TAGS`),
									'#SQL.Body#', t.`SQL.Body`)
									
						;
						*/
					END IF;
					
					IF _MODE  = "Execute.statements" THEN
					--	Teraz stworz cursor na takie zagniezdzone pozycje i dla kazdej zawolaj rekurencyjnie
						BEGIN
							DECLARE done BOOL DEFAULT FALSE;
							DECLARE _SQL_EXECUTE MEDIUMTEXT;
							DECLARE _LP VARCHAR(150);
							DECLARE c_proc CURSOR FOR
								SELECT 
									s.LP,
									s.`SQL.EXE`
								FROM `t_browser.sql.statements` s
								WHERE 
									TRUE
								ORDER BY LP
							;
							DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
							OPEN c_proc;
							loop_idnNg_merge: 
							LOOP
								FETCH c_proc INTO _LP, _SQL_EXECUTE;
								IF done THEN
									LEAVE loop_idnNg_merge;
								END IF;
								
								SET @_SQL_EXECUTE = _SQL_EXECUTE;
								CALL _PrepareSQLText_with_HashParams('Fill.content', @_SQL_EXECUTE, '', @_f_Value_Down, '', @.sql.Err, @.sql.INFO, '', '');	
								SET _SQL_EXECUTE = @_SQL_EXECUTE;
								
								UPDATE `t_browser.sql.statements` s
								SET
									s.`SQL.EXE` = _SQL_EXECUTE
								WHERE	
									s.LP = _LP
								;
								SET @_SQLText = _SQL_EXECUTE;
								CALL _ExecuteCmd(_SQL_EXECUTE, @Error);
							END LOOP;
							CLOSE c_proc;
						END;
					END IF;
	
	IF _MODE = 'SQL.GET.SQL' THEN
		SELECT
			GROUP_CONCAT(t.`SQL.Exe` ORDER BY t.LP SEPARATOR '\n/* ================================================= */ \n') AS `SQL_EXE`
		FROM `t_browser.sql.statements` t
		;
		
	END IF;
	
END$$

DROP PROCEDURE IF EXISTS `_Editor_SQL_Exe`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `_Editor_SQL_Exe`(
	IN _MODE VARCHAR(250),
	IN _SESSION VARCHAR(150),
	IN _Key VARCHAR(150),	
	IN _Key2 VARCHAR(150),	
	IN _Key3 VARCHAR(150),
	IN _IN_Params MEDIUMTEXT,
	INOUT _SQL MEDIUMTEXT,
	IN _Param_A VARCHAR(250),	
	IN _Param_B VARCHAR(250),	
	IN _Param_C VARCHAR(250),	
	IN _Param_D VARCHAR(250),
	IN _Param_E VARCHAR(250)	
)
/*
*/

S_Editor_SQL_Exe: BEGIN 
	DECLARE	_Id_browser, _AliasName, _ID_SQL, _Context, _TableName, _KeyFieldName, _KeyValue VARCHAR(150);
	DECLARE	_Limit, _MaxTime VARCHAR(250);
	DECLARE _PrfGUID_c, _PrfGUID_f, _PrfGUID_p, _PrfGUID_d VARCHAR(38);
	DECLARE _Idn INTEGER;

	CALL _sys_authorization('SESSION.CHECK.is.NULL', _SESSION, '', '', '', '', 'GO');
SET @.TESTOWANIE._Editor_SQL_Exe = 1;	


	IF _MODE IN ('GET.Fields.to.APPLY', 'NEW.GET.Fields.to.APPLY') THEN
		SET
			_ID_Browser = _Key
		;
		SET	@_ID_Browser = _ID_Browser;
		SELECT
			c.Col_NameAs AS EditFieldName,
			c.GUI_FieldType,
			_sys_browsers_col_to_html(c.GUI_FieldType) AS HTML_FieldType
		FROM `_sys_browsers_col` c
		-- INNER JOIN `_sys_browsers_sect` s ON s.ID_Browser = c.ID_Browser AND s.Kind = 'UPDATE' AND IFNULL(s.Update_Key_Table_FieldName, '') <> '' AND IFNULL(s.Update_Key_Col_NameAs, '') <> '' 
		WHERE
			c.ID_Browser = @_ID_Browser
			AND (c.Editable)
		GROUP BY c.GUID
		UNION
		SELECT
			c.Col_NameAs AS EditFieldName,
			c.GUI_FieldType,
			_sys_browsers_col_to_html(c.GUI_FieldType) AS HTML_FieldType
		FROM `_sys_browsers_sect` s
		-- było INNER JOIN `_sys_browsers_col` c ON c.ID_Browser = s.ID_Browser AND c.col_Alias = s.sect_AliasName AND c.Col_NameAs = s.Update_Key_Col_NameAs
		INNER JOIN `_sys_browsers_col` c ON c.ID_Browser = s.ID_Browser 
			AND 
			c.Col_NameAs IN (Update_KeyValue_col_NameAS, Update_KeyValue_col_NameAS_2, Update_KeyValue_col_NameAS_3)
		WHERE
			c.ID_Browser = @_ID_Browser
			-- AND s.Kind = 'UPDATE'
			-- AND IFNULL(s.Update_KeyValue_col_NameAS, '') <> ''
		GROUP BY c.GUID
		;
	END IF;
		
	IF _MODE = 'APPLY.Table' THEN
		SET
			_ID_Browser = _Key
		;
		SET	@_ID_Browser = _ID_Browser;
		DROP TEMPORARY TABLE IF EXISTS `t_alias_names`;
		CREATE TEMPORARY TABLE `t_alias_names`
		/* było
				SELECT
					c.col_Alias AS IN_col_Alias
				FROM `_sys_browsers_col` c
				WHERE
					c.ID_Browser = @_ID_Browser
					AND c.Editable
				GROUP BY IN_col_Alias
		*/
			SELECT
				IFNULL(c.Update_Alias, c.col_Alias) AS IN_col_Alias
			FROM `_sys_browsers_col` c
			WHERE
				c.ID_Browser = @_ID_Browser
				AND c.Editable
			GROUP BY IN_col_Alias
			;
		BEGIN
			DECLARE IN_col_Alias VARCHAR(150);
			DECLARE done BOOL DEFAULT FALSE;
			DECLARE c_proc CURSOR FOR
			SELECT 
				a.IN_col_Alias
			FROM `t_alias_names` a
			;
			DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
			OPEN c_proc;
			  loop1: LOOP
				FETCH c_proc INTO IN_col_Alias;
				IF done THEN
					LEAVE loop1;
				ELSE
					CALL _Editor_SQL_Exe('NEW.APPLY.1.Alias', _SESSION, _ID_Browser, IN_col_Alias, _Key3, _IN_Params, _SQL, _Param_A, _Param_B, _Param_C, _Param_D, _Param_E);
				END IF;
			END LOOP;
			CLOSE c_proc;
		END;
		
	END IF;

	IF _MODE = 'NEW.APPLY.1.Alias' THEN
		/*
			Zapis 1 z wielu tabel 1..n
		*/
		SET
			_ID_Browser = _Key,
			_AliasName = _Key2
		;
		SET @Sznurek = _IN_Params, @_ID_Browser = _ID_Browser, @_AliasName = _AliasName;
		-- SHOW CREATE TABLE `t_curr_alias` ;
		DROP TEMPORARY TABLE IF EXISTS `t_curr_alias`;
		CREATE TEMPORARY TABLE `t_curr_alias` (
		  `GUID` VARCHAR(38) NOT NULL DEFAULT '' COMMENT 'Klucz glowny',
		  `Id_browser` VARCHAR(200) NOT NULL DEFAULT '' COMMENT 'ID z `_sys_browsers_n` ale nie koniecznie',
		  `Kind` VARCHAR(250) NOT NULL DEFAULT '' COMMENT 'typ pozycji "FROM","LEFT","INNER" tabele, "WHERE","HAVING","LIMIT","GROUP BY","ORDER BY" etc.',
		  `TableName` VARCHAR(250) NOT NULL DEFAULT '' COMMENT 'nazwa tabeli gdy Typ = "FROM","LEFT","INNER"',
		  `AliasName` VARCHAR(250) NOT NULL DEFAULT '' COMMENT 'n.p. "k" w `kontrah` k UWAGA `AliasName` zawiera to co `Typ`  zawiera dla "WHERE","HAVING","LIMIT" etc. ',
		  `_COL_SET` TEXT,
		  `_COL_SELECT` TEXT,
		  `sect_Expr` MEDIUMTEXT COMMENT 'wyrazenie SQL np. w LEFT JOIN wszystko co ma byc w ON ... / dodatkowe w WHERE itd',
		  `Update_KeyFieldName` VARCHAR(250) DEFAULT NULL COMMENT 'Kolumna klucza/UID tabeli jesli bedzie podlegala zapisowi',
		  `Update_KeyValue_col_NameAS` VARCHAR(250) DEFAULT NULL COMMENT 'Kolumna klucza/UID tabeli jesli bedzie podlegala zapisowi',
		  `Update_KeyFieldName_2` VARCHAR(250) DEFAULT NULL COMMENT '2. opcjonalna kolumna klucza/UID tabeli jesli bedzie podlegala zapisowi',
		  `Update_KeyValue_col_NameAS_2` VARCHAR(250) DEFAULT NULL COMMENT '2. opcjonalna kolumna klucza/UID tabeli jesli bedzie podlegala zapisowi',
		  `Update_KeyFieldName_3` VARCHAR(250) DEFAULT NULL COMMENT '3. opcjonalna kolumna klucza/UID tabeli jesli bedzie podlegala zapisowi',
		  `Update_KeyValue_col_NameAS_3` VARCHAR(250) DEFAULT NULL COMMENT '3. opcjonalna kolumna klucza/UID tabeli jesli bedzie podlegala zapisowi',
		  PRIMARY KEY GUID(GUID)
		)
		;
		TRUNCATE `t_curr_alias` ;
		INSERT IGNORE INTO `t_curr_alias` 
		SELECT
			s.GUID, s.Id_browser, s.Kind, 
			(@_TableName := s.sect_TableName) AS TableName,
			s.sect_AliasName AS AliasName, 
			'' AS _COL_SET, '' AS _COL_SELECT,
			s.sect_Expr,
			s.Update_KeyFieldName,
			s.Update_KeyValue_col_NameAS,
			s.Update_KeyFieldName_2,
			s.Update_KeyValue_col_NameAS_2,
			s.Update_KeyFieldName_3,
			s.Update_KeyValue_col_NameAS_3
			
		FROM `_sys_browsers_sect` s 
		WHERE
			s.ID_Browser = @_ID_Browser
			AND s.sect_AliasName = @_AliasName
			AND s.Update_KeyFieldName IS NOT NULL
			AND s.Update_KeyValue_col_NameAS IS NOT NULL
		LIMIT 1
		;
		-- SELECT * FROM `t_curr_alias` ;
		
		/*
		SELECT 
			s.Sect_TableName
		FROM `_sys_browsers_sect` s
		WHERE
			s.ID_Browser = @_ID_Browser
			AND s.sect_AliasName = @_AliasName
			AND IFNULL(s.Sect_TableName, '') <> '' 
			AND s.Kind = 'UPDATE'
			AND IFNULL(s.Update_Key_Table_FieldName, '') <> '' 
			AND IFNULL(s.Update_Key_Col_NameAs, '') <> ''
		LIMIT 1
		INTO
			_TableName
		;
		SET @_TableName = _TableName;
		*/
		SET @_TableName = @_TableName;
		SET _TableName = @_TableName;
set @.watch.apply = null;		
set @.watch.apply = concat_ws('/', @.watch.apply, '1');
		
		DROP TEMPORARY TABLE IF EXISTS `t_modify_cols`;
		-- show CREATE TABLE `t_modify_cols`;
		CREATE TEMPORARY TABLE `t_modify_cols` (
			`Editable` BOOLEAN DEFAULT FALSE,
			`IS_WHERE_Field` BOOLEAN DEFAULT FALSE,			-- np. NULL zapisujemy do pla NOT NULL lub inne okoliczności np. PRIMARY KEY etc.
			`Edit_FieldName` VARCHAR(250) NOT NULL DEFAULT '',	-- Col_NameAs - tak jest w sznurku
			`Update_FieldName` VARCHAR(250) NOT NULL DEFAULT '',	-- Col_Name - kolumna w zrodlowej tabeli 
			`Update_Key_FieldName` VARCHAR(250) NOT NULL DEFAULT '', -- Kolumna klucza/UID tabeli jesli bedzie podlegala zapisowi
			`AliasName` VARCHAR(250) NOT NULL DEFAULT '',
			`TableName` VARCHAR(250) NOT NULL DEFAULT '',		-- Tabla
			`SQL_UPDATE_FieldName` VARCHAR(250) NOT NULL DEFAULT '',	-- kolumna w zrodlowej taveli z aliasem
			`SQL_WHERE_FieldName` VARCHAR(250) NOT NULL DEFAULT '',	-- kolumna w zrodlowej tabeli z aliasem
			`SQL_UPDATE_Expr` LONGTEXT,
			`SQL_SELECT_Expr` LONGTEXT,
			`SQL_WHERE_Expr` LONGTEXT,
			`Skip_Update` BOOLEAN DEFAULT FALSE,			-- np. NULL zapisujemy do pla NOT NULL lub inne okoliczności np. PRIMARY KEY etc.
			`Field_Value` LONGTEXT,								-- Fetch
			`Field_Value_IS_NULL` BOOLEAN DEFAULT FALSE,
			`GUI_FieldType` VARCHAR(20) NOT NULL DEFAULT '',
			`inf_FieldExists` BOOLEAN,							--	czy istnieje w information_schema.`COLUMNS`
			`inf_DATA_TYPE` VARCHAR(64) DEFAULT '',			--	DATA_TYPE z information_schema.`COLUMNS`
			`inf_IS_NULLABLE` BOOLEAN DEFAULT FALSE,			--	IS_NULLABLE z information_schema.`COLUMNS`
			`inf_COLUMN_DEFAULT` LONGTEXT,					--	COLUMN_DEFAULT z information_schema.`COLUMNS`
			`inf_IS_MUERIC` BOOLEAN DEFAULT FALSE,				--	okreslone na podstawie `NUMERIC_PRECISION` z information_schema.`COLUMNS`
			-- (DATA_TYPE = 'date' OR IFNULL(DATETIME_PRECISION >= 0, FALSE) OR NOT IFNULL(NUMERIC_PRECISION >= 0, FALSE) ) AS NEED_QUOTE,
			`inf_NEED_QUOTE` BOOLEAN DEFAULT TRUE,					--	okresla czy bedzie wartosc 'value' tekst lub czas czy value dla numerycznych
			PRIMARY KEY `Edit_FieldName`(`Edit_FieldName`),
			KEY `TableName`(`TableName`),
			KEY `Update_FieldName`(`Update_FieldName`)
		)
		;
		TRUNCATE `t_modify_cols`; 			
		INSERT IGNORE INTO `t_modify_cols`
			SELECT
				c.Editable,
				-- FALSE AS IS_WHERE_Field,
				FALSE AS IS_WHERE_Field,
				c.Col_NameAs AS Edit_FieldName,
				IFNULL(c.Update_FieldName, c.Col_Name) AS Update_FieldName,
				'' AS Update_Key_FieldName,	
				-- było IFNULL(c.Update_Alias, c.col_Alias) AS AliasName,
				s.AliasName AS AliasName,
				s.TableName AS TableName,
				
				-- c.sql_colref AS SQL_UPDATE_FieldName,
				'' AS SQL_UPDATE_FieldName,
				'' AS SQL_WHERE_FieldName,
				'' AS SQL_UPDATE_Expr,
				'' AS SQL_SELECT_Expr,
				'' AS SQL_WHERE_Expr,
				FALSE AS Skip_Update,
				NULL AS Field_Value,
				TRUE AS Field_Value_IS_NULL, 
				c.GUI_FieldType,
				FALSE AS inf_FieldExists,
				'' AS inf_DATA_TYPE,
				FALSE AS inf_IS_NULLABLE,
				NULL AS inf_COLUMN_DEFAULT,
				FALSE inf_IS_MUERIC,
				TRUE inf_NEED_QUOTE
			FROM `t_curr_alias` s
			INNER JOIN `_sys_browsers_col` c ON
				c.ID_Browser = s.ID_Browser		
				AND IFNULL(c.Update_Alias, c.col_Alias) = s.AliasName
			GROUP BY c.GUID
		;
		INSERT IGNORE INTO `t_modify_cols`
			SELECT
				c.Editable,
				-- FALSE AS IS_WHERE_Field,
				TRUE AS IS_WHERE_Field,
				c.Col_NameAs AS Edit_FieldName,
				'' AS Update_FieldName,
				'' AS Update_Key_FieldName,	
				s.AliasName AS AliasName,
				s.TableName AS TableName,
				
				-- c.sql_colref AS SQL_UPDATE_FieldName,
				'' AS SQL_UPDATE_FieldName,
				'' AS SQL_WHERE_FieldName,
				'' AS SQL_UPDATE_Expr,
				'' AS SQL_SELECT_Expr,
				'' AS SQL_WHERE_Expr,
				FALSE AS Skip_Update,
				NULL AS Field_Value,
				TRUE AS Field_Value_IS_NULL, 
				c.GUI_FieldType,
				FALSE AS inf_FieldExists,
				'' AS inf_DATA_TYPE,
				FALSE AS inf_IS_NULLABLE,
				NULL AS inf_COLUMN_DEFAULT,
				FALSE inf_IS_MUERIC,
				TRUE inf_NEED_QUOTE
			FROM `t_curr_alias` s
			INNER JOIN `_sys_browsers_col` c ON
				c.ID_Browser = s.ID_Browser		
				AND IFNULL(c.Col_NameAs IN (s.Update_KeyValue_col_NameAS, s.Update_KeyValue_col_NameAS_2, s.Update_KeyValue_col_NameAS_3), FALSE)
			GROUP BY c.GUID
		ON DUPLICATE KEY UPDATE
			IS_WHERE_Field = TRUE
		;
		DELETE te FROM `t_modify_cols` te WHERE te.Editable = 0 AND te.IS_WHERE_Field = 0;
		
		UPDATE `t_modify_cols` te, `t_curr_alias` s
		SET
			te.Update_Key_FieldName =
				IF(IFNULL(te.Edit_FieldName IN (s.Update_KeyValue_col_NameAS, s.Update_KeyValue_col_NameAS_2, s.Update_KeyValue_col_NameAS_3), FALSE),
					IF(te.Edit_FieldName = s.Update_KeyValue_col_NameAS,
						s.Update_KeyFieldName,
						IF(te.Edit_FieldName = s.Update_KeyValue_col_NameAS_2,
							s.Update_KeyFieldName_2,
							IF(te.Edit_FieldName = s.Update_KeyValue_col_NameAS_3,
								s.Update_KeyFieldName_3,
								''
							)
						)
					),
					''
				 )
		;
		UPDATE `t_modify_cols` te, `t_curr_alias` s
		SET
			te.SQL_UPDATE_FieldName = 
				IF(te.Editable = 1,
					CONCAT(te.AliasName, '.', te.Update_FieldName),
					''
				),
			te.SQL_WHERE_FieldName =
				IF(te.IS_WHERE_Field = 1,
					CONCAT(te.AliasName, '.', te.Update_Key_FieldName),
					''
				)
			
		;
	--	Sprawdz istnienie kolumn w information_schema	
		UPDATE `t_modify_cols` te, information_schema.`COLUMNS` ic
		SET
			te.inf_FieldExists = TRUE,
			te.inf_DATA_TYPE = ic.DATA_TYPE,
			te.inf_IS_NULLABLE = (ic.IS_NULLABLE = 'YES'),
			te.inf_COLUMN_DEFAULT = ic.COLUMN_DEFAULT,
			te.inf_IS_MUERIC = IFNULL(ic.NUMERIC_PRECISION >= 0, FALSE),
			te.inf_NEED_QUOTE = 
				(ic.DATA_TYPE = 'date' OR IFNULL(ic.DATETIME_PRECISION >= 0, FALSE) OR NOT IFNULL(ic.NUMERIC_PRECISION >= 0, FALSE)),
			te.Field_Value = 
				_Params2('_FetchParams.Sznurek', @_ModeParam := '', @Sznurek, te.Edit_FieldName, '')
		WHERE
			ic.TABLE_SCHEMA = SCHEMA()
			AND ic.TABLE_NAME = @_TableName -- te.TableName -- 
			AND ic.COLUMN_NAME IN (te.Update_FieldName, te.Update_Key_FieldName)
		;
	--	Usun nieistniejace	
		DELETE c FROM `t_modify_cols` c WHERE NOT c.inf_FieldExists;
	--	Ustaw puste
		UPDATE `t_modify_cols` te
		SET
			te.Field_Value_IS_NULL = (te.Field_Value IS NULL),
			te.Skip_Update = 
			((te.Field_Value IS NULL) AND NOT te.inf_IS_NULLABLE)	-- gdy NULL i zapisujemy do pla NOT NULL 
			OR
			(FALSE)	--	na razie bo dojda inne warunki - np. PRIMARY KEY etc.
		;
	-- 	SQL_UPDATE_Expr i SQL_SELECT_Expr,
		UPDATE `t_modify_cols` te
		SET
			te.SQL_UPDATE_Expr = 
				CONCAT_WS(' = ', 
					te.SQL_UPDATE_FieldName, 
					IF(te.Field_Value_IS_NULL, 
						'NULL',
						IF(te.inf_NEED_QUOTE,
							QUOTE(te.Field_Value),
							IF(te.inf_IS_MUERIC,
								IFNULL(NULLIF(te.Field_Value, ''), IF(te.inf_IS_NULLABLE, 'NULL', 0)),
								te.Field_Value
							)
						)
					)
				),
			te.SQL_SELECT_Expr = te.SQL_UPDATE_FieldName
		WHERE
			te.Editable
			AND NOT te.Skip_Update	--	np. NULL zapisujemy do pola NOT NULL lub inne okoliczności np. PRIMARY KEY etc.
		;
		-- SQL_WHERE_Expr,
		UPDATE `t_modify_cols` te
		SET
			te.SQL_WHERE_Expr = 
				CONCAT_WS(' = ', 
					te.SQL_WHERE_FieldName, 
					IF(te.Field_Value_IS_NULL, 
						'NULL',
						IF(te.inf_NEED_QUOTE,
							QUOTE(te.Field_Value),
							te.Field_Value
						)
					)
			)
		WHERE
			te.IS_WHERE_Field
		;
		-- SELECT * FROM `t_modify_cols` te WHERE te.IS_WHERE_Field;
		SET @_COL_SET = NULL;
		SET @_COL_SET = (
			SELECT
				GROUP_CONCAT(
					CONCAT('  ', te.SQL_UPDATE_Expr)
					SEPARATOR ',\n'
				)
			FROM `t_modify_cols` te
			WHERE
				te.Editable
				AND NOT te.Skip_Update	--	np. NULL zapisujemy do pola NOT NULL lub inne okoliczności np. PRIMARY KEY etc.
		)
		;
		SET @_COL_SELECT = NULL;
		SET @_COL_SELECT = (
		SELECT
			GROUP_CONCAT(
				CONCAT('  ', te.SQL_SELECT_Expr)
				SEPARATOR ',\n'
			)
		FROM `t_modify_cols` te
		WHERE
			te.Editable
			AND NOT te.Skip_Update	--	np. NULL zapisujemy do pola NOT NULL lub inne okoliczności np. PRIMARY KEY etc.
		)
		;

		
	--	Zanim zrobie psie ucha na value to pobiore saute wartość do ewen. klucza do zapis w logu	
		IF _Param_E LIKE '%LOGPO%' THEN
set @.watch.apply = concat_ws('/', @.watch.apply, 'LOGPO');
			SELECT
				te.Field_Value
			INTO _KeyValue
			FROM `t_modify_cols` te
			WHERE
				te.IS_WHERE_Field
			LIMIT 1
			;
			SET @_KeyValue = _KeyValue;
		--	 i jeszcze lista pol do porownan w `logpo`
 			CALL _Two_comapare_Rec_TempTables_To_LOG('Create.`t_FieldNames`', 1, '', '', '', '', '', '');
			INSERT IGNORE INTO `t_FieldNames` 
			SELECT
				te.Update_FieldName
			FROM `t_modify_cols` te
			WHERE
				te.Editable
				AND NOT te.Skip_Update	--	np. NULL zapisujemy do pola NOT NULL lub inne okoliczności np. PRIMARY KEY etc.
			;
set @.watch.apply = concat_ws('/', @.watch.apply, 'LOGPO.end');
		END IF;
		
		SET @_KEY_WHERE = NULL;
		SET @_KEY_WHERE = (
		SELECT
			GROUP_CONCAT(
				CONCAT('  ', te.SQL_WHERE_Expr)
				SEPARATOR ',\n'
			)
		FROM `t_modify_cols` te
		WHERE
			te.IS_WHERE_Field
		)
		;
		
		SET
		@_UPDATE_SQL =
"
UPDATE `#TableName#` #ALIAS_NAME#
SET
#COL_SET#
WHERE
#KEY_WHERE#
;
"
		;
		SET
			@_UPDATE_SQL = REPLACE(@_UPDATE_SQL, '#TableName#', @_TableName)
				
		;
		SET
			@_UPDATE_SQL = REPLACE(@_UPDATE_SQL, '#ALIAS_NAME#', @_AliasName)
		;
		SET
			@_UPDATE_SQL = REPLACE(@_UPDATE_SQL, '#COL_SET#', @_COL_SET)
		;
		SET
			@_UPDATE_SQL = REPLACE(@_UPDATE_SQL, '#KEY_WHERE#', @_KEY_WHERE)
		;
		SET
		@_Select_SQL =
"
CREATE TEMPORARY TABLE `t_OLD_rec`
SELECT 
*	
FROM `#TableName#` #ALIAS_NAME#
WHERE
#KEY_WHERE#
;
"
		;
		SET
			@_Select_SQL = REPLACE(@_Select_SQL, '#TableName#', @_TableName)
		;
		SET
			@_Select_SQL = REPLACE(@_Select_SQL, '#ALIAS_NAME#', @_AliasName)
		;
		SET
			@_Select_SQL = REPLACE(@_Select_SQL, '#COL_SELECT#', @_COL_SELECT)
		;
		SET
			@_Select_SQL = REPLACE(@_Select_SQL, '#KEY_WHERE#', @_KEY_WHERE)
		;
		
-- LEAVE S_Editor_SQL_Exe;
		
		
		
	--	SELECT @_Select_SQL;
	-- 	SELECT @_COL_SELECT;
		IF _Param_E LIKE '%LOGPO%' THEN
		/******************************************************************************
			I odczyt z bazy aktualnego wiersza przed UPDATE - za chwilke to beda stare dane (`t_OLD_rec`)
		******************************************************************************/
set @.watch.apply = concat_ws('/', @.watch.apply, 'LOGPO.2');
			DROP TEMPORARY TABLE IF EXISTS `t_OLD_rec`;
			CALL _ExecuteCmd(@_Select_SQL, @Error);
set @.watch.apply = concat_ws('/', @.watch.apply, 'LOGPO.2.end');
		END IF;
		/******************************************************************************
			Zapis do bazy	
		******************************************************************************/
		-- LEAVE S_Editor_SQL_Exe;
		CALL _ExecuteCmd(@_UPDATE_SQL, @Error);
		IF _Param_E LIKE '%LOGPO%' THEN
		/******************************************************************************
			II odczyt z bazy aktualnego wiersza sa to nowe dane (`t_NEW_rec`) 
			- uwaga musze podmienic nazwe tabeli w @_Select_SQL z OLD na NEW
		******************************************************************************/
set @.watch.apply = concat_ws('/', @.watch.apply, 'LOGPO.3.1');
			DROP TEMPORARY TABLE IF EXISTS `t_NEW_rec`;
			SET
				@_Select_SQL = REPLACE(@_Select_SQL, '`t_OLD_rec`', '`t_NEW_rec`')
			;
set @.watch.apply = concat_ws('/', @.watch.apply, 'LOGPO.3.2');
			CALL _ExecuteCmd(@_Select_SQL, @Error);
		--	Zapis do `log` i `logpo`
			SET _Idn = NULL;		set @.MY.Last.Idn = NULL;
		set @._SESSION = _SESSION, @._TableName = _TableName, @._KeyValue = _KeyValue;
			CALL log_Insert('INS.Session', _Idn, _SESSION, _TableName, '200', _KeyValue, '', 'EDYCJA', _TableName);
set @.watch.apply = concat_ws('/', @.watch.apply, 'LOGPO.3.3');
			SET @.MY.Last.Idn = _Idn;
			
			CALL _Two_comapare_Rec_TempTables_To_LOG('Prepare.Schema.with.`t_FieldNames`', 0, '', _TableName, 't_OLD_rec', 't_NEW_rec', '', '');
set @.watch.apply = concat_ws('/', @.watch.apply, 'LOGPO.3.4');
			CALL _Two_comapare_Rec_TempTables_To_LOG('`logpo`<-`t_fields_DBSCHEMA_To_LOG`', _Idn, '', '', '', '', '', '');
set @.watch.apply = concat_ws('/', @.watch.apply, 'LOGPO.3.5');
			
		END IF;
		
		IF _Param_E LIKE '%SELECT%' THEN
			SELECT
				@_UPDATE_SQL,
				@_SELECT_SQL,
				@_COL_SET,
				@_COL_SELECT,
				@.MY.Last.Idn
			;
		END IF;
		
	END IF;

END$$
		
DELIMITER ;

/*
====================================================================================================================================================================================
	NOTATNIK
====================================================================================================================================================================================

Zasada prosta literaly oczywiste podawane wprost a fakultatywne (join where, having) w [ ] 
Mamy sekcje
[COLUMNS] 		kolumny
[COLUMNS.AGG] 	kolumny agregacyjne
[FROM]
[JOIN]
[WHERE]			concat where.S. i where.f
[WHERE.key]		concat where.S. i where.f i where.key
[WHERE.MaxTime]	concat where.S. i where.f i WHERE.MaxTime
[GROUP]
[HAVING]
[ORDER]
[LIMIT]
ponadto nazwy Tablel
<temptable.name>
<temptable.name.check>
<temptable.name.key>
<temptable.name.maxtime>
<temptable.name.information_schema>
<temptable.name.tags>

SELECT
- zwykly
""
""
"SELECT[SQL_CALC_FOUND_ROWS]\n[COLUMNS]\n-- EXT1\n-- EXT2\nFROM [FROM]\n[JOIN]\nWHERE\n[WHERE][GROUP][HAVING][ORDER][LIMIT]\n;"
""

SELECT
- z temp
"DROP TEMPORARY TABLE IF EXISTS `<temptable.name>` \n;"
"CREATE TEMPORARY TABLE IF NOT EXISTS `<temptable.name>` \nSELECT[SQL_CALC_FOUND_ROWS]\n[COLUMNS]\n-- EXT1\n-- EXT2\nFROM [FROM]\n[JOIN]\n[WHERE][GROUP][HAVING][ORDER][LIMIT]\n"
"SELECT * FROM `<temptable.name>`\n;"
""

SELECT AGG -> TYLKO TEMP
- temp
""
"" -- "CREATE TEMPORARY TABLE IF NOT EXISTS `<temptable.name>` \nSELECT[SQL_CALC_FOUND_ROWS]\n[COLUMNS]\n-- EXT1\n-- EXT2\nFROM [FROM]\n[JOIN]\n[WHERE][GROUP][HAVING][ORDER][LIMIT]\n"
"SELECT\n[COLUMNS.AGG] * FROM `<temptable.name>`\n"
"DROP TEMPORARY TABLE IF EXISTS `<temptable.name>` \n"

[SELECT]
									`temptable.name` VARCHAR(250) NOT NULL DEFAULT '',
									`temptable.name.check` VARCHAR(250) NOT NULL DEFAULT '',
									`temptable.name.maxtime` VARCHAR(250) NOT NULL DEFAULT '',
									`temptable.name.key` VARCHAR(250) NOT NULL DEFAULT '',
									`temptable.name.information_schema` VARCHAR(250) NOT NULL DEFAULT '',
									`temptable.name.TAGS` VARCHAR(250) NOT NULL DEFAULT '',

								"SELECT", "SELECT.TEMP", "SELECT.AGG", "SELECT.KEY", "SELECT.MAXTIME", "SELECT.TAGS", "SELECT.information_schema"
1 ost. komentarz
2 ost. komentarz
3 ost. komentarz
*/
