2024년 2월 29일 목요일

code snipper 예제

<pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; 
                color: #000000; background-color: #eee;
                font-size: 12px; border: 1px dashed #999999;
                line-height: 14px; padding: 5px; 
                overflow: auto; width: 100%">
       <code style="color:black;word-wrap:normal;">
            CODE HERE
       </code>
</pre>
<div>code snipper 아래 본문</div>

HTML Input Number type disable scroll

const MyNumberInput = () => {
  const numberInputOnWheelPreventChange = (e) => {
    // Prevent the input value change
    e.target.blur()

    // Prevent the page/container scrolling
    e.stopPropagation()

    // Refocus immediately, on the next tick (after the current     
    function is done)
      setTimeout(() => {
        e.target.focus()
    }, 0)
}

  return <input type="number" onWheel={numberInputOnWheelPreventChange}/>
}       

mysql 프로시저에서 파라미터로 받은 값을 IN 구문에 사용하여 인덱스 이용하기

프로시저에서 파라미터로 받은 값은 FIND_IN_SET으로만 검색이 가능한데, 이럴 경우 INDEX를 타지 않고 Full Search를 진행한다.

IN 구문을 사용하려면 쿼리 전체를 문자열로 만들어서 수행해야한다.

DROP PROCEDURE IF EXISTS ABC.admin_SelectData;
/*
    CALL ABC.admin_SelectData('');
*/
DELIMITER //
CREATE PROCEDURE ABC.admin_SelectData(
    IN _ids NVARCHAR(256),
    IN _types NVARCHAR(128),
    IN _beginDateTime DATETIME(3),
    IN _endDateTime DATETIME(3)
)
BEGIN

    SET @_sql = 'SELECT * FROM ABC.Data WHERE ';
    SET @_sql = CONCAT(@_sql, ' rewardDateTime >= \'', _beginDateTime, '\' AND rewardDateTime < \'', _endDateTime, '\'');
    SET @_sql = CONCAT(@_sql, ' AND ID IN (', _ids, ')');
    IF _types IS NOT NULL THEN
        SET @_sql = CONCAT(@_sql, ' AND type IN (', _types, ')');
    END IF;

    SET @_sql = CONCAT(@_sql, ' GROUP BY userID ORDER BY reward DESC LIMIT 1;');
    PREPARE PSQL FROM @_sql;
    EXECUTE PSQL;
    DEALLOCATE PREPARE PSQL;

END //
DELIMITER ;

위와 같이 CONCAT을 이용해서 쿼리 문자열을 만들고, PREPARE와 EXECUTE를 이용하여 실행시켜주면 된다.