Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to configure cursor class for Flask-mysql #28

Closed
hamzanaseem54345 opened this issue Dec 20, 2017 · 10 comments
Closed

how to configure cursor class for Flask-mysql #28

hamzanaseem54345 opened this issue Dec 20, 2017 · 10 comments

Comments

@hamzanaseem54345
Copy link

i tried adding as app.config['MYSQL_CURSOR'] = 'DictCursor' & app.config['MYSQL_DATABASE_CURSOR'] = 'DictCursor' but did not work please help confused.

@ghost
Copy link

ghost commented Dec 31, 2017

Hi, part of my code is here. it works. i hope it can be useful:

#config mysql
mysql = MySQL()

app.config['MYSQL_DATABASE_HOST'] = "localhost"
app.config['MYSQL_DATABASE_PORT'] = 3306
app.config['MYSQL_DATABASE_USER'] = 'root'
app.config['MYSQL_DATABASE_PASSWORD'] = 'root'
app.config['MYSQL_DATABASE_DB'] = 'hiflaskdb'
#app.config['MYSQL_DATABASE_CHARSET'] = 'utf-8'
mysql.init_app(app)
@app.route('/register', methods=['GET','POST'])
def register():
	form = RegisterForm(request.form)
	if request.method=='POST' and form.validate():

		name = form.name.data
		email = form.email.data
		username=form.username.data
		password = sha256_crypt.encrypt(str(form.password.data))

		conn=mysql.connect()
		cursor = conn.cursor()
		cursor.execute("INSERT INTO users(name, email, username, password) VALUES(%s,%s,%s,%s)",(name, email, username, password))

		#commit to DB
		conn.commit()

		cursor.close()

		flash('You are registered and can log in!','success')

		return redirect(url_for('index'))


	return render_template('register.html', form=form)	


When i finished all crud operations i will publish my project you can look at on my github page:
https://github.com/kayace

@bbkane
Copy link

bbkane commented Jan 22, 2018

I need this too- @kayace we're trying to access the cursor types PyMySQL exposes ( specifically this one. Looking at the code, it doesn't appear to be possible. @cyberdelia would you accept a pull request if I added this?

@ghost
Copy link

ghost commented Jan 22, 2018 via email

@ghost
Copy link

ghost commented Jan 22, 2018 via email

@bbkane
Copy link

bbkane commented Jan 22, 2018

@kayace what should I send you?

@ghost
Copy link

ghost commented Jan 22, 2018 via email

@bbkane
Copy link

bbkane commented Jan 22, 2018

@kayace I'm asking the maintainer (@cyberdelia ) if they will accept a pull request to implement this feature (adding a MYSQL_DATABASE_CURSOR_TYPE to the config's values so @h54345 and I can use DictCursor with our connections). I don't want to do the work and @cyberdelia not merge my new feature, so I want his blessing before I start. I wish you could help me, but I really need him. Thanks!

@cyberdelia
Copy link
Owner

@bbkane Sure.

@bbkane
Copy link

bbkane commented Jan 26, 2018

@cyberdelia I'll try to work on it this weekend

@bbkane
Copy link

bbkane commented Dec 30, 2019

Whoops, kinda forgot about that. Sorry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants