I am new in stackoverflow. Also, please forgive me for my english.
I have a question about using timestamp in MySQL stored proc. I am using MySQL 5 and MySQLdb Python module (Python version 2.6). Here is a code to create my stored procedure:
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;")
When I am trying to create this proc, everything is ok. But, when i am calling this proc, I am getting an error. Here is a call of this procedure:
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 (and endDate) I get this:
time = datetime.datetime(2012, 07, 25, 8, 00, 00)
startDate = str (time)
Here is the an error:
..._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)
Where is my mistake? If it possible, please give an example, of using the "timestamp" in MySQL stored proc.
Thanks in advance.