thanks, It's work
It was on this 2 line :
SET valueName = CONCAT(valueName, ' ,', _valueSplit);
SET valueValue = CONCAT(valueValue,' ,', json(_entryData, _valueSplit));
I have declared the variable, but at NULL so CONCAT return NULL and the query go on NULL to
thanks to Devart for helping me
when I try to use my Stored Procedure I have this error
call _extract() Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NULL' at line 1
but I see nothing in the procedure this my procedure, but no instruction NULL on it
CREATE PROCEDURE _extract()
BEGIN
DECLARE _entryType VARCHAR(45);
DECLARE _entryData VARCHAR(1024);
DECLARE _entryTime BIGINT(20);
DECLARE no_more_rows BOOLEAN;
DECLARE num_rows INT DEFAULT 0;
DECLARE entryCursor CURSOR FOR SELECT entryValue, entryTime FROM TrackingEntry;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET no_more_rows = TRUE;
OPEN entryCursor;
select FOUND_ROWS() into num_rows;
mainLoop: LOOP
FETCH entryCursor INTO _entryData, _entryTime;
IF no_more_rows THEN
CLOSE entryCursor;
LEAVE mainLoop;
END IF;
SET _entryType = json(_entryData, "type");
CALL split_string(json(_entryData, "data"), ",");
CALL _extractJson(_entryType, _entryData);
END LOOP mainLoop;
END$$
_extractJson procedure : the next part of the extration of the data
CREATE PROCEDURE _extractJson(`_entryType` VARCHAR(255))
BEGIN
DECLARE _valueSplit VARCHAR(255);
DECLARE valueName VARCHAR(255);
DECLARE valueValue VARCHAR(255);
DECLARE split_no_more_rows BOOLEAN;
DECLARE split_num_rows INT DEFAULT 0;
DECLARE splitCursor CURSOR FOR SELECT SQL_CALC_FOUND_ROWS _value FROM SplitValues;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET split_no_more_rows = TRUE;
OPEN splitCursor;
select FOUND_ROWS() into split_num_rows;
dataLoop: LOOP
FETCH splitCursor INTO _valueSplit;
IF split_no_more_rows THEN
CLOSE splitCursor;
LEAVE dataLoop;
END IF;
SET valueName = CONCAT(valueName, ' ,', _valueSplit);
SET valueValue = CONCAT(valueValue,' ,', json(_entryData, _valueSplit));
END LOOP dataLoop;
SET @query = CONCAT('INSERT INTO ',_entryType, ' (',valueName,') VALUES (',valueValue,')' );
PREPARE stmt FROM @query;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
--end stuffs here
END$$
to explain what i want to do
some Data are stored in trackingEntry, each row contain information about what the user do (in a social game) and where he come from (action, referer, and some other value)
theses data are stored in a Json format like that : { "type" : "tableName", "data" : "row1,row2,row3", "row1" : "value", "row2" : "value", "row3" : "value" }
the type of the data (the action (connection, publish on wall)) it's a table's name of one of our dashboard application
The "data" is the list of the available datas
and after we have the Datas
You have to add SQL_CALC_FOUND_ROWS
in the select statement, so that the FOUND_ROWS()
function works.
So change this line
DECLARE entryCursor CURSOR FOR SELECT entryValue, entryTime FROM TrackingEntry;
like this
DECLARE entryCursor CURSOR FOR SELECT SQL_CALC_FOUND_ROWS entryValue, entryTime FROM TrackingEntry;
You can read more about it here .
The problem can be with a prepared INSERT statement, it seems that one of the variables is NULL. Try to comment prepared statements and select @query, you will see the problem -
SET @query = CONCAT('INSERT INTO ',_entryType, ' (',valueName,') VALUES (',valueValue,')' );
SELECT @query;
-- PREPARE stmt FROM @query;
-- EXECUTE stmt;
-- DEALLOCATE PREPARE stmt;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.