python


MYsql Stored procedure only work the second time i execute it through python


I'm using python to create a data warehouse in MySQL.
I'm using the MySQLdb package to connect python to MySQL.
I am trying to create a table which will contain all dates from 2005 to 2018.
First, I create the relevant table:
cursor.execute("""
CREATE TABLE IF NOT EXISTS dim_date (
date_id int(11) NOT NULL AUTO_INCREMENT,
date date,
day int(11),
month int(11),
year int(11),
day_name varchar(45),
PRIMARY KEY (date_id),
INDEX date_index (date))
""")
Then, I run the following command to create and run the stored procedure that will fill in the dates:
cursor.execute("DROP PROCEDURE IF EXISTS BuildDate;")
cursor.execute("SET #currdate := '2005-01-01';")
cursor.execute("SET #enddate := '2018-01-01';")
cursor.execute("""
CREATE PROCEDURE BuildDate()
BEGIN
WHILE #currdate < #enddate DO
INSERT INTO ntr_yelp_dw.dim_date (date, day, month, year, day_name)
VALUES (
#currdate, DAY(#currdate), MONTH(#currdate),
YEAR(#currdate), DAYNAME(#currdate)
);
SET #currdate := DATE_ADD(#currdate, INTERVAL 1 DAY);
END WHILE;
END
""")
cursor.callproc("BuildDate")
The thing is that when I run the stored procedure code, the stored procedure is created, but the data isn't filled.
Only when I run it a second time, the data is created and inserted into the table.
Any thoughts?


Related Links

Pymongo Regex match with list
Python 2.7 The 'packaging' package is required; normally this is bundled with this package
EOF Error Pickle
Graphviz: write result to file
Debug behavior differ from normal execution in python
nodejs unable to pass more than one arguments to the script with spawn
Setting indents while writing to an xml. Python.
Python Numpy's argsort duplicate issue [duplicate]
How to write Python script like shell script for UNIX?
Why does pythons slice indexing give counter intuitive results? [duplicate]
How to solve “Insufficient Permission” for userUsageReport with Google API?
Python: TypeError: 'list' object is not callable on global variable
sudo/suid non-root nesting fails
Difference between a list & a stack in python?
Python continue Not Working Properly
list where multiple values have to be found and replaced with two new values

Categories

HOME
spring
angular-cli
windows-store-apps
specflow
ll
gspread
filter
subquery
currency
pjsip
spinnaker
webmethods
phoenix
alfresco-share
flexlm
propel2
jive
statusbar
uiautomator
esql
header-files
maximo
pptp
spring-data-neo4j
classpath
system.data.sqlite
weinre
hibernate-cache
piecewise
oracle-xml-db
division
remote-server
css-counter
openshift-enterprise
xen
forecasting
elfinder
equivalence
jquery-multidatespicker
cross-entropy
exiftool
stereo-3d
cppunit
asmx
aqgridview
maintenance
tomee
radians
pax-web
linkageerror
kendo-combobox
fps
selecteditem
concur
handlebars.java
except
windows-vista
wikitext
sevenzipsharp
manjaro
rx-groovy
git-checkout
stackframe
virus
robocode
sysfs
pl-i
gyroscope-framework
mser
node-inspector
snmp4j
log4cplus
bounds
android-json-rpc
.net-cf-3.5
asp.net-mvc-scaffolding
leptonica
dllexport
jqmobi
grunt-contrib-compass
shortcuts
arbor.js
symfony-2.0
file-exists
emacs23
easygui
smooth
nvelocity
unreachable-code
winverifytrust
webrat
method-signature
handheld
standardized
self-reference
rd





Mobile Apps Dev
Database Users
javascript
java
csharp
php
android


MS Developer
developer works
python
ios
c
html
jquery


RDBMS discuss