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

Reading numpy arrays outside of Python
Return value from thread
Is this control structure a code smell?
Django: How do I validate unique_together from within the model
Munging non-printable characters to dots using string.translate()
Error when using astWCS trying to create WCS object
if there any better way to read bb function souce code.i was very faint
PyQt4 signals and slots
Sql Alchemy What is wrong?
How do I plot a graph in Python?
Reordering matrix elements to reflect column and row clustering in naiive python
making urllib request in Python from the client side
Grid within a frame?
how to create http headers from scratch
Mapping a range of values to another
maya2008 win32api 64 bit python

Categories

HOME
jsf
cil
nlp
sed
performancecounter
google-tag-manager
vs-team-services
aem
formal-verification
hana
jscript
ll
iis-7.5
browserify
httpclient
google-plus
xamarin-studio
rfid
game-physics
gwtp
uisplitviewcontroller
shippo
flexboxgrid
sql-update
raphael
tampermonkey
croppic
switching
guile
dhtmlx-scheduler
cell-array
gpib
lmdb
smart-mobile-studio
ipfw
oracle-xml-db
pdflatex
modelandview
service-locator
sidr
color-scheme
discord.net
dql
cppunit
fastq
python-idle
lumen-5.3
azure-availability-set
decompress
collapsingtoolbarlayout
garrys-mod
iostat
uistackview
debugdiag
wcf-ria-services
mix
try-finally
foxit
uiprogressview
qregexp
kendo-menu
fabric-twitter
virus
es2015
django-1.6
rhel5
microblaze
dmp
cg
ghostdoc
dto
valence
map-force
mbox
reserved-words
logentries
symphony-cms
zend-lucene
ubuntu-11.10
css-tables
radchart
pstree
mpmovieplayer
nintendo
hashalgorithm
django-nose
associative
phpcrawl
zend-form-element
hadoop-plugins
external-assemblies
winverifytrust
graniteds
oggvorbis
filetime
graph-layout
callgrind
longjmp
nt4
inline-if
associativity

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App