1
새 소개입니다. 또한 영어로 제발 용서해주세요.MySQL 저장 프로 시저에서 timestamp를 사용하는 방법
MySQL 저장 프로 시저에서 timestamp 사용에 관한 질문이 있습니다. MySQL 5 및 MySQLdb Python 모듈 (Python 버전 2.6)을 사용하고 있습니다.
나는이 시저를 만들려고하고def create_procedure_sum_shift():
global cursor
cursor.execute("CREATE PROCEDURE `sum_shift`\
(IN s_Time DATETIME, IN e_Time DATETIME)\
BEGIN\
SET @q = concat('SELECT * FROM trig_test WHERE `t_stamp`>=',\
s_Time,' AND `t_stamp` <= ', e_Time);\
PREPARE query FROM @q;\
EXECUTE query;\
deallocate prepare query;\
END;")
, 모든 것이 괜찮 : 은 여기 내 저장 프로 시저를 만들 수있는 코드입니다. 그러나이 proc을 호출 할 때 오류가 발생합니다.
def call_sum_shift(startDate, endDate):
global cursor
cursor.execute("call sum_shift(DATE('%s'),DATE('%s'));" % (startDate, endDate))
rows = cursor.fetchall()
discr = cursor.description
return rows,discr
의 startDate (와 endDate가) 나는이 얻을 : 여기 이 절차의 호출입니다
다음time = datetime.datetime(2012, 07, 25, 8, 00, 00)
startDate = str (time)
(가) 오류입니다 :
..._mysql_exceptions.ProgrammingError:(1064,"You have an error...for the right syntax to use near '00:00:00 AND `t_stamp` <= 2012-07-25 00:00:00` at line 1)
내 실수는? 가능한 경우, MySQL 저장 프로 시저에서 "타임 스탬프"를 사용하는 예제를 제공하십시오.
미리 감사드립니다.
또한 저장 프로 시저에서 [SQL injection] (http://en.wikipedia.org/wiki/SQL_injection)을주의하십시오. – Vatev