#databases
1 messages Β· Page 53 of 1
well.. it is good practice in any case..
alright
how is your database connection setup?
so, you get the username from somewhere, you should run something like this
not sure your users table is called users
are you using python 3.6+?
Yup, python 3.6 π
In Python, there are several ways to do string interpolation, including using %s's and by using the + operator to concatenate strings together. However, because some of these methods offer poor readability and require typecasting to prevent errors, you should for the most part be using a feature called format strings.
In Python 3.6 or later, we can use f-strings like this:
snake = "Pythons"
print(f"{snake} are some of the largest snakes in the world")
In earlier versions of Python or in projects where backwards compatibility is very important, use str.format() like this:
snake = "Pythons"
# With str.format() you can either use indexes
print("{0} are some of the largest snakes in the world".format(snake))
# Or keyword arguments
print("{family} are some of the largest snakes in the world".format(family=snake))
Ah I see, haven't used Python in ages. Thanks.
you should also consider not storing the password in the database
oh well, only for me to mess around with π
oh.. damn.. i did not look at the screenshot
No, do it right or don't do it
How else do you do it?
You can use the variable insertion provided by whatever SQL driver you're using
mysql.connector
here i am trying to get you to not store password and open a SQL injection...
cursor.execute("... WHERE x = %s", (username, ))
Right I've got accountdetails.execute("SELECT * FROM accountinformation WHERE username=f{input_username}") at the moment. How would I change it to the other version?
Look at my example and try to adapt it
Alright
@terse stump I don't think the MySQL connector uses ?
Maybe you can use both though
I dunno
I think i have used it in mysql.. but then again, I do not use mysql if i do not have to
I mean, I wouldn't write SQL if I had the choice of an ORM
I guess it does use ? instead of %s then
That doesn't seem to work either.
This is mysqlclient? (import MySQLdb ?)
Ohh
Cuz input_username needs to be a triple
*tuple
(input username, )
Make sure u include the ,
@hallow coral
Ah okay
Should work, if it doesnβt I have no idea π
(Make sure u use %s as the placeholder not ? for MySQLdb)
@terse stump sorry for late response i was on meeting
what I am trying to do is connect the sqlite with discord
so user would apply username to database
and than inside different commands there would be a username check
if user has already applied or not
now when I run a check command
it works and I get returned what it was stored in udner my username
however if the table is empty
or my username not stored in one of the rows
nothing is returned
but the idea would be that bot would send message for example
You need to sign in first
well yes, nothing is returned if there's nothing matching
you just need to check that
All working π
accountdetails.execute("SELECT * FROM accountinformation WHERE username=%s", (input_username, ))
@hallow coral Just chiming in to say that this
accountdetails.execute("SELECT * FROM accountinformation WHERE username=f{input_username}") # SUPER BAD```
is security **suicide**. Don't ever use string interpolation (`+` operator, `.format`, f-strings) to build queries, but do indeed use the % placeholders of an execute or SQL building statement of your ORM
Yup, already been made aware of that. Thank though!
what if input_username = "'john' OR 1=1; DROP TABLE accountinformation; --"
π
https://www.xkcd.com/327/
the tale of Bobby Tables, any SQL database user should remember this comic by heart π
I'm trying to insert/update records into a table using SQLAlchemy, and my table reflection is not working with the UniqueConstraint that I have passed in, along with the PrimaryKeyConstraint as well. My code looks like this, am I doing something wrong? myTable = Table('TableName', metaTable, PrimaryKeyConstraint('fieldName1', 'fieldName2'), UniqueConstraint('fieldName1', 'fieldName2'), autoload=True, autoload_with=engineDatabase, extend_existing=True)
So i'm using MySQL Workbench... and i'm trying to create a datawarehouse
Is it possible to run a query..
Export Results into another database?
Creating it as well...
I'm pretty much a noob when it comes to all this, so sorry if something is really obvious, and I'm missing it. I have a program that can output data via ODBC, so I would like to setup a MySQL server to receive the data. I plan on using Python to handle the analysis later. I downloaded the MySQL installer and installed the server. I didn't add any user accounts during the setup phase, so all I have is the root user. I see the ODBC setup in Windows' control panel, but I can't really figure out how it works or how to get it to work. Any help would be much appreciated.
Maybe I shouldn't even be using this "Data Source Administrator" because the MySQL server isn't really the data source?
Heyo,
I'm doing the following query on my DB
SELECT * FROM table ORDER BY column_name DESC
The problem is that this query only retrieves 1 line.
How can I retrieve several lines ?
Are you sure that's the issue as to why you're getting 1 line?
That would just mean that table only has 1 row
here is a screenshot of my code
And here is one of my DB
the Table has 1538 lines
it happens :P
Anyone know if python can write to an existing firebase database project?
if u have a valid gateway to the specific database then yes
but u would have to import a specific module for that ( forgot , u will need to research about that )
@torn sphinx hmm okay thanks
Where is a great place to start with databases, just learn the basics of SQL?
I was wondering does anyone know of a good (preferably free) file hosting site that allows uploading through python?
this is probably the wrong channel to ask that in
yeah, certainly not a database question
Dropbox and Google Drive both offer that functionality and have some degree of free storage
I'm not intimately familiar with any others
Amazon S3
Dropbox I am intimately familiar with if u want help with that
Itβs kinda complicated if u wanna upload a file not in a single request
@tender fern lookup installing MySQL tutorial on Ubuntu by digitalocean
And then also look at digitaloceans tutorial on using MySQL
Anyone ever run into an issue like this? I'm trying to add my local SQL Server as a data host, but it isn't coming up in the dropdown menu, and I can't get it to work when I type something like "localhost\MySQL80"
Im having trouble coming up with a good way to store who sent and who recieved a message because i have 2 different user classes
class Chats(db.Model):
__tablename__ = "chats"
id = db.Column(INTEGER, primary_key=True)
talent_id = db.Column(INTEGER(db.ForeignKey('users.id')))
startup_id = db.Column(INTEGER(db.ForeignKey('startups.id')))
startup_user_id = db.Column(INTEGER(db.ForeignKey('startup_users.id')))
messages = db.relationship('Messages')
class Messages(db.Model):
__tablename__ = "messages"
id = db.Column(INTEGER, primary_key=True)
Hey, I'm kinda getting into using python and databases together but I got a problem, could someone help me with it?
cursor = cnxn.cursor()
cursor.execute("INSERT INTO discordusers (username, password, rank, division, discordid) VALUES ('Testing', 'Testing2', 'Testing3', 'Testing4', 'Testing5');")
row = cursor.fetchone()
``` this is the code and the error I'm getting is No results. Previous SQL was not a query. But it does work within acces without python
@wind nexus Rather than having 2 distinct types of user objects why not have 1 user class with a parameter like user_type or user_role to differentiate them.
using microsoft acces
@boreal carbon What are you expecting to get from your query? It's an insertion.
I realised it when i heard the beep
okay I guess I asked too soon π
thanks regardless
Huzzah! π
@fathom crater lthe reason i have different user classes is because im using a relations and the login system is different for both,
I'm not suggesting you don't have different behaviour but typically with a relational database you want to normalize your data as much as possible. Having 2 different user types in 2 different tables is going to make your life harder. It's just as effective to have 1 table with a isStartup value that you use in your code to switch login behaviour.
also some people might use same email for being a user and a startup users
well i just did this and now i feel dirty
class Chats(db.Model):
__tablename__ = "chats"
id = db.Column(INTEGER, primary_key=True)
talent_id = db.Column(INTEGER, db.ForeignKey('users.id'))
startup_id = db.Column(INTEGER, db.ForeignKey('startups.id'))
startup_user_id = db.Column(INTEGER, db.ForeignKey('startup_users.id'))
sent_by_startup = db.relationship('Startup_Messages')
sent_by_talent = db.relationship('Talent_Messages')
class Startup_Messages(db.Model):
__tablename__ = "startup_messages"
id = db.Column(INTEGER, primary_key=True)
chat_id = db.Column(INTEGER, db.ForeignKey('chats.id'))
message = db.Column(TEXT(500))
date_sent = db.Column(DATETIME, default=datetime.utcnow)
seen = db.Column(BIT, default = False)
class Talent_Messages(db.Model):
__tablename__ = "talent_messages"
id = db.Column(INTEGER, primary_key=True)
chat_id = db.Column(INTEGER, db.ForeignKey('chats.id'))
message = db.Column(TEXT(500))
date_sent = db.Column(DATETIME, default=datetime.utcnow)
seen = db.Column(BIT, default = False)
i had a user class a bit like this before :
class Users(UserMixin, db.Model):
__tablename__ = "users"
user_id = db.Column(INTEGER, primary_key=True)
email = db.Column(VARCHAR(255), index=True, unique=True)
password_hash = db.Column(VARCHAR(255))
is_startup = db.Column(BIT, default=False)
talent_details = db.relationship('Details', uselist=False, back_populates='user')
startup = db.relationship('Startups', uselist=False, back_populates='user')
otp_secret = db.Column(VARCHAR(255))
All I can say is you asked for a "good way" and the good way is database normalization. Your ORM reflects the database and in this case there's no magic way to make it less "dirty" without refactoring the data first.
hmm, thats a good point
maybe my current user class is too specialized for single type of users
well time to refactor again, lets hope i can still meet the deadline next month
almost all main func is still missing :/
im getting major impostor syndrome fibes atm
from myself
Has anyone here used PonyORM with PostgresQL before? I'm having the issue where everything except object.to_json() works, which errors with pony.orm.core.PermissionError: The current user None which belongs to groups ['anybody'] has no rights to see the object User['4970937813479959015'] on the frontend
fix ur db settings
I tried
but I can create tables and insert just fine
the password and username should work
I am
db.bind(provider='postgres', **kwargs) with kwargs as py func(user=SETTINGS["DB_USER"], password=SETTINGS["DB_PASS"], database="Sayonika", host=SETTINGS["DB_HOST"])
make sure the kwargs are correct, i guess
make sure the value u passed isn't None
it's not, I set it earlier
SETTINGS = {
# Default
"DB_HOST": "localhost",
"DB_USER": "mart",
"DB_PASS": "my_pass"
}
and password was set with ALTER USER mart WITH PASSWORD 'my_pass';
π€ add more prints lmao
So apparently I should use to_dict instead
I have SQL Server 8.0 installed, but I can't get an instance of it to show up in Microsoft SQL Server Manager
Any ideas? Most of the posts I see online are made by people who apparently didn't install SQL Server 8.0
But I see that I have an instance running and can login and do stuff like make tables.
Nothing shows up in SSCM either
I just reinstalled Server 8.0. Same issue
So i've got a MySQL Database for all my users about 250k rows of data (16-20 Tables)
I've got one data analyst who analyses the data using Microsoft Excel ...
We're planning on moving over to Amazon Redshift
Does anyone have any software reccommendations that can just connect to a database as a Read ONLY but have the ability to adjust/edit the data client-side only?
Helloooo, I'm confused by your question. So you want read only perms in sql and in your front-end software adjust/edit perms?
Python Friends, I need advices.
My bot is going to use a Database.
For now (bot is still in dev) i'm using a local SQLite db.
Do you think it's worth to use a GCP database ?
The things i'll be storing in the db are critical for my bot features
and i'm afraid that some sort of bug could wipe the SQLite local db
does the operation to a GCP db takes time ? or is rather fast (~0.2 sec) ?
The bot will be hosted on GCP aswell
I recommend PostgreSQL because it's always been perfectly reliable for me, GCP not sure
The best module for MySQL is pymysql right ?
I'm connecting a program to MS SQL via ODBC. The program that is sending the data to MS SQL is able to see tables on the SQL server, but all it shows are ones in the default "master" database. Is this normal? It says that there are 502 of them.
I can't see the "test" database, I made. Perhaps it is being crowded out by all of these tables in the "master" database?
They are ones like "master.sys.database_files" and "master.sys.database_audit_specification_details"
Tons of them
No, I don't think there is a limit to the number of tables I can have. I just created one in the master database, and it is accessible by the program sending the data.
So now the issue is that my ODBC connection only sees master tables
Nevermind. I figured it out
@lilac sundial Yes
HENLO Anyone use NoSQL/Document store Databases? If so which?
Do you guys know any modules for creating SQL statements from objects, for example sometihng like this:
dict = {col1:val1,col2:val2}
print( Statement.InsertInto(dict,"my_db.mytable") )
----------------------------------------------------------------
INSERT INTO my_db.mytable
(`col1`,`col2`)
VALUES
('val1','val2')```
Anyone have any idea how to install scrapy
?
Do I need to mess with my environmental path if Iβm using conda ?
Please dm me thanks
!t no-dms
no-dms is an unknown tag name. Please check the spelling and try again.
!t no-dm
Can I send you a private message?
No. We do not provide one-on-one tutoring - you can hire someone locally if you really need that. We also prefer that questions are answered in a public channel as it means that everyone else present is able to learn from them. If you're working with code that you are unable to disclose for any reason, you should try to make your question more general and write a separate, small piece of code to illustrate your problem.
furthermore, why dont you just try the normal way and use pip? @analog forge
and even more interesting, why is this related to #databases ?
i am facing a problem with pysqlcipher3
i downloaded the clone from github
and i did this
python setup.py build
from terminal
and i have this error: command 'cl.exe' failed: No such file or directory
windows 10
CL is Visual Studio's compiler from what I remember, I assume you'll to download something that embeds it. Your best bet is to download the VS20xx compiler
Any thoughts on pyodbc vs pypyodbc?
Hey I ran this sql command on sqlite 3
f"""SELECT * FROM people WHERE strftime('%m', birth_day) = '{month}'"""
why are there so many """
It doesn't give me the results in order
its and sql command
shouldn't it be like that
it works.. it just doesn't give it to me in order.
what do you mean?
Select id, name from users
[('Name 1', 'male', '2005-10-30', 'Null', '00-00-00'), ('Name 2', 'male', '2005-10-04', 'Null', '00-00-00'), ('Name 3', 'male', '2005-10-12', 'Null', '00-00-00')]
This is the output it gives when the month is 10
I want it to give it out in the order of date.. for example:
oh lemme try that
it works!
thanks
i though there had to be a clause in the WHERE statement that puts it in order
if you replace ASC with DESC it sorts in the other direction
thanks for helping me out π
no problem
for column in Cursor.execute ("SELECT * FROM Playersname WHERE username = ?",(Name)"AND password = ?",(password)";"):
Cursor.execute("sql query"(1)= Name,(2)=Password)```
i am trying to insert the variable name into the ? of the dataase query for the Username and i am trying to insert the Variable password into password
can someone tell me how to do this
it isnt working at all
MySQL?
Ah k nvm idk :/ iβd try and help but I donβt trust myself on 0h sleep π
okay thanks anyway
Hello,
I just encounter something weird in a MySQL db: image directly stored within the dabatase. I mean, not the path to the image, the actual data of the image
Am I missing some genius or the person who did that is a total dummy?
@slate night That's not quite what i suggested you do last time we went over it.
firstly you weren't supposed to directly write "sql query"
Ohhh I just copied and pasted what you said I thought you said to do that
I know I thought you just said that I know I want to learn
but the ? i had within the query were meant to be ? s
as they are placeholder symbols in sqlite (for python interaction) at least
Yeah then how do I replace them
so you could pass Name and Password as parameters to execute
to fill those placeholders
execute("sqlstuff ... name = ?", Name)```
Here the first ? gets replaced with the value of Name
Hello,
I just encounter something weird in a MySQL db: image directly stored within the dabatase. I mean, not the path to the image, the actual data of the image
Am I missing some genius or the person who did that is a total dummy?
Heβs a dummy
Just because you can do it doesnβt mean u should π
@chrome fjord
Be careful about casting stones at other devs, you don't know the particulars. There are reasons (https://www.microsoft.com/en-us/research/publication/to-blob-or-not-to-blob-large-object-storage-in-a-database-or-a-filesystem) (admittedly old) that someone might have chosen to store binary data in a database. I'm not saying @chrome fjord's dev made a good or bad choice but in the absence of information let's encourage systematic review over maligning someone else's intellect.
Application designers often face the question of whether to store large objects in a filesystem or in a database. Often this decision is made for application design simplicity. Sometimes, performance measurements are also used. This paper looks at the question of fragmentatio...
To blob or not to blob lmao π
reminds me of google noto's "The blobs are dead. Long live the blobs!"
I usually store BLOBs too
why?
More scalable on multi-server instances
And most db system feature optimizations for storing BLOBs, so that was never much of an issue, except the size of the DB maybe
hmmm
: )
So i've gotta export a database MySQL into Redshift JDBC every night
I was hoping to do this all with python?
Is it possible to run a python script get all table names then for each table get the data structure?
as well as sometimes get the data
Want the structure mostly incase the tables change over time
Hey @dull scarab just got to my pc
i added that thing you said and it worked now getting this error
line 15, in querying
for column in Cursor.execute ("SELECT * FROM Playersname WHERE username = ?",Name, "AND password = ?",Password):
TypeError: function takes at most 2 arguments (4 given)```
for column in Cursor.execute ("SELECT * FROM Playersname WHERE username = ?",Name "AND password = ?",Password):
they are to passed as a tuple at the end, without splitting up the query iirc
("query eruy stuff = ? and thing = ?", (123, "abc")```
(1, 2) tuple of 1 and 2
iirc, if i remember correctly
ohh so at the end
oh great that worked
so how can i do if the password is wrong it prints invalid password
@dull scarab
Technically, for security reasons you shouldn't give any different response if either username or password is incorrect. But if you want to do it remove password from the query, fetch the username and check manually if the password matches
but what if the user wants to know if there password was correct or incorrect?
wasnt that how i was doing it before
ahhhh okay
thats ok thanks guys for your help
i may ask for more later on but i am ok for now
This... some strange
Pretty common task in python
So i can get list of my table in tuples
is it possible to convert to a string list?
You can use a string like a list in of one character strings in a lot of places
Is it possible to export MySQL Tables like this:
DROP TABLE IF EXISTS broadcategory CASCADE;
CREATE TABLE broadcategory
(
broadcategoryid integer NOT NULL,
value varchar(65535)
);
COMMIT;
Instead of like this:
CREATE TABLE `broadcategory` (
`BroadCategoryID` int(11) NOT NULL AUTO_INCREMENT,
`Value` varchar(15) DEFAULT '',
PRIMARY KEY (`BroadCategoryID`)
ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=latin1
Is it possible to have something in python a long the lines of
For x in TableName
print x.column and x.type ?
you can get results as a dict i think
if you do the thing that gets you tuples you could do
for column, type in result
is value a keyword in MySQL?
sql syntax highlighting is weird
i was just asking
i think there are words that have a meaning in some contexts that get highlighted because the syntax parser isn't smart enough
because i named a column value and now i get syntax error
no i meant double quotes
` works too in mysql but isn't part of the ansi sql standard so i tend not to recommend it
but value is a column, not a string
strings are in single quotes
some sql engines let you sometimes use double quotes for strings, but use as a column/table name takes priority
because ansi
(but, sure, use `value` if you want
ok
(surround with `` and spaces to code-quote something containing ` in markdown)
oh wait, my problem is with key, not value
that makes more sense, since key is definitely a keyword
well maybe
oracle doesn't care, oddly enough
i think the oracle parser may be more contextual than the mysql one
oh well, thanks anyways
As an aside, to explain what i'm talking about: there are two ways to do parsers for languages that have "keywords" (i.e. identifier-like words that have a special meaning in the syntax) - non-contextual (the lexer classifies the keyword immediately, and it's banned from use as an identifier for everywhere) or contextual (the keyword is only recognized where it makes sense - note that this does not mean a language cannot be a "context free grammar")
i got chu
@nova hawk ill try with tuples
As of now - I've left work
But I've managed to search for the though all types
Convert most to varchar
Just gotta create a create a query with it for create table
I think that was a near-miss with your click there, #data-science-and-ml :P
Maybe explain what your project is about as well
well it just looks like a survey
It is a survey
So i have this:
print("""DROP TABLE IF EXISTS %s CASCADE;
\nCREATE TABLE %s
(""" % (x,x))
for x,y in zip(tableFields, Tabletype):
if(x == (tableFields[-1])):
print(" "+x+" "+y)
else:
print(" "+x+" "+y+",")
print(");\n\n")
DROP TABLE IF EXISTS usertoken CASCADE;
CREATE TABLE usertoken
(
UserTokenID int(11),
UsersID int(11),
Token varchar(250),
Expiry datetime
);
Which gives me that...
How can i make that into a Cursor.execute?
store it as a string instead of printing it
then cursor.executescript(my_sql_string)
well, that's what it would be for sqlite at least
How?
there's several tables
would that be a case of creating a list of strings?
stringone[0].append
stringone[0].append
stringone[0].append
Stringone[1].append
Stringone[1].append
Stringone[1].append
sorta thing?
you could create a list of strings or you could just append all to 1 string
i just did
query_list = [""] * len(str_tables)
Whats the best data format use on mssql when storing output time.time()?
Does anyone know how to get SELECT * from table
results
so its like
INSERT INTO c1,c2,c3,c4 ('3232','434','33','4')
? Can you rephrase that question.
Sound like your looking for SELECT INTO @mystic surge
Thanks @unique mauve Ted
hey all
is it possible to do a mysql query to find the latest table thats currently or has been updated without providing a specific table name?
Which module do you guys uses for Postgres DBs ? psycopg2 or pygresql ?
Asyncpg 
oh
But i've mostly only used it in an asynchronous environment
I'm trying to connect to a local mongodb database, but apparently I can't even get the simplest script to work properly. The error output is AttributeError: 'Post' object has no attribute '_is_document', but that must be from the mongoengine library and I don't know how to fix it.
from mongoengine import *
connect('test')
class Post(Document):
title = StringField(max_length=120, required=True)
author = StringField(max_length=120, required=True)
tags = ListField(StringField(max_length=30))
post1 = Post(title="Hello, world!", author="John", tags=["flask", "mongoengine"])
post1.save()
@dull scarab Do you know how to use SSL with AsyncPG ?
@barren glacier your code is working for me what python do you use?
3.7
installed mongoengine with pip3 ?
yes. What version of mongodb do you use?
Come to think of it, that can't be the problem...the error comes from mongoengine
tested it on python 3.5.3 and mongoDB 3.2.11
Thanks, I'll setup a new environment and test it again. If the code is alright, the problem must be on my side. Thanks for checking
what version is your mongoengine btw ?
mongoengine had some issues with python 3.7 so maybe just upgrading mongoengine will get it working for you
I've just installed mongoengine yesterday, must be 0.15.3 then
pymongo is 3.7.1 and six is 1.11
got the same except pymongo is 3.7.2 for me
Alright, it works for me with python 3.5.3. I'll test it with 3.6.6 now, see how that goes. Must have been the python version then. Thanks for your help, Quiz
edit: python 3.6.6 works fine as well
no problem
has anyone here used PonyORM before? having issues with many-to-many relations
For MongoDB (using Motor + PyMongo as the client) a way to pass a custom function in the find() call? My use case is doing fuzzy matching for a specific field and currently I'm doing the bad thing of loading everything to do the comparisons.
Hey how can I sort a query by number of child rows? I have a Product that has offers, each offer has it's own table. I'm displaying those list of products on a html table , and the amount of offer available for a product. I want the user to be able to sort that table by clicking on the header. I want to be able to do something like Product.query.order_by(len(Product.offers)) , and sorting by ascending or descending. I'm also using pagination.
I'm using Flask + Sqlalachemy
anyone have an idea how to produce a counter such as A A B D E T A into 1 1 2 3 4 5 1. so that it group and do counter on each group
I am currently working with panda in spyder
i need this to run loop through the data frame for each group. please ping me if you haven an answer
I don't know how to attempt this problem because the most syntax i know that might work so far is df1[:,'counter']=df1.groupby('class').cumcount() but it's not the right answer to it
I have a question and I want to see if I understand these concepts correctly in a metaphorical sense:
We have a relational database on cakes
The domain would be the cake store
The attributes Columns could be anything from cake ingredients, price of cakes, location of store
The values would be the exact ingredients of the cake, or the exact price of the cake or the exact location of the cake store.
Now the relational part would be connected through any of these domains or attributes or attributes and if we wanted to find out more info on these domains or attributes or values we can go to another table interconnected to one of these and find out the prices and/or other names of cake stores within that table?
Your questions is a little hard to understand, can you rephrase it? Break it up so it's easier to swallow and such
Okay, will do when Iβm at a computer
Actually I just want to make a comparison between relational databases and a metaphor:
Our relational database is what holds all of our data and can be referenced to another table right?
Our metaphor:
Our earth is equivalent to the domain of a relational database
A human on earth is equivalent to an attribute of a relational database
Height, weight, name, etc. of the human . is equivalent to a value in a relational database
That humans friends or weight values or the type of planet they live on could be related to another table that points to another humans weight, friends or planet they live on?
@hallow jetty
That sounds right tbh
There's probably someone that knows more than me that will pop in though
Okay, phew. Thank you!
Hello. I am beginner in python and learning it since a week now. At the same time i am learning i am trying to develop at the same time.
For now, i am at the step of reading and extracting data from a json file. And i want to stock my extraction in DB for future usage (web dev).
What would be the best ? Mysql or mamgonosql (with BSON) ?
I have read the differences in theory but i wanted to know your experiences with those,
BSON is Binary JSON
Ok thank you
test
amazing
Is there any way to make a .mdb file with sqlite3?
@indigo goblet mdb is for access, what are you trying to do?
what's better for a messenger - Scylla or Postgres?
Storing huge amounts of messages (history) with optional images, videos and other embeds, servers+settings, people+settings,etc., you might've got the hint
for storing messages and stuff, id use postgres
include like a time with each message, and groupid and userid
and you can search for stuff really quickly
maybe like a contenttype, so if its a video, the text is the path to the image or something
thats how ive done mine
Hi, how can I host json file in heroku postgress ?
what is the best database for storing food like if i want to make a yogurt api for school
someone pls @ me
Depends how big this db is to be I suppose
If its through django / flask they probably haave their own database systems you could use
@full geyser "you know, like discord", and they use Cassandra
aherm
Hey is this channel open?
I got my script to work with SQLite but switched to MySQL and am getting an error now.
in defaulterrorhandler
raise errorclass(errorvalue)
ProgrammingError: not all arguments converted during string formatting
which I get from this line:
c.execute(PutExcelInSQL, myrow)
and to make that make sense, I'm going to paste in a little more of that block so you can see how I formatted my SQL and what myrow looks like (I'm iterating through rows of excel worksheets in workbooks)
PutExcelInSQL = '''INSERT INTO Raw_Data(ID,Peptide,Peaks_Probability_Score,ppm,m_over_z,RT,Scan,Accession,PTM,Mass,pI,Length,Aliphatic_Index,Net_Charge,Hydropathy,Charge_Per_Residue,SVM_Class,SVM_AMP_Prob,RF_Class,RF_AMP_Prob,DA_Class,DA_AMP_Prob,Filename,Myrowid,UniqueID,Species,Date_Raw_Data_Acquired,Location,Author) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)'''
if DBColumnCheck(myrow) is True:
try:
c.execute(PutExcelInSQL, myrow)
are you sure that you have the same amount of params as items in myrow?
I'll double check, but I did count those before
29 values, 29 question marks
tried to run it again, same issue.
and row is a tuple of values, right?
wait, does mysql even use ? for params
wasn't it %s in mysql?
myrow? myrow is a row in excel
that it, that I can't use '?' ?
if I change ? to %s, is that going to make it vulnerable to that injection attack thing.....
no, not if you do it properly
properly as in not by using 'INSERT INTO whatever VALUES (%s)' % values but rather 'INSERT INTO whatever VALUES (%s)', values
let me know how it turns out
oh ok I get a different error now π
do show
OperationalError: (1366, "Incorrect Integer value: '>0' for column 'ID' at row 1")
so I look at that and think I told SQL to make the first column primary key autoincrement but I need to add a column there for that to go in because it's trying to do that with my first column of data from excel
im surprised mysql gives you an error for incorrect values
so you want to drop the first row from excel or the first column?
i thought what you were suggesting was that you just want to use the autogenerated id
What I want is to fix each error as they come up until this works :P
I want to keep the ID column from excel. I want to be able to insert the entire row of data, row by row. What I have is set up to do that. (just, switching from sqlite to mysql and it will work)
I think what I need to do is put a column in first, for the primary key. then make sure my data gets inserted after that. right?
wait a second let me try something
why do making changes to databases take FOREVERRRRRRRRr. I want to be coming back here saying "Hey I fixed it" but I can't do that until I can see if the change I made fixes it.
@eager nest just leave the id column out of the insert query?
i.e. insert into Raw_Data(Peptide,...)
has anyone used Redis as a database ?
its for my web game server
its only gonna be storing some highscores and stuff
seems like key-value store like redis might be enough

what is the best database server for security? Does not need to be great speed wise.
someone said PostgreSQL but wondering if there is anything better? (never done databases)
need help
@quiet ermine depends on your requirements
postgres has a pretty extensive security model, i think even row-level
basically as secure as possible without it taking forever to process, aes256/sha256 ideally (forgot what one you need for this)
sorry if phrasing is a bit off, new to databases & just starting out with django
do you want an encrypted data directory?
no idea
could always run it in a vm in the server
(will only ever be acessed by 1 website)
i still have no idea what youβre asking
do you want to restrict access to the database? encrypt the data?
then iβm not sure how to answer your question, the general go-to nowadays is postgres
π
@quiet ermine there are 2 types of security volcyy mentioned
Retricting access is more about your servers security: (Who can access it, network security etc)
Data security is encrypting the data so that its useless without the correct keys
saying you want it to be "secure" is a little vague, as there are so many levels of "secure"
i like to use random library to randomize every byte of my database to make sure no one can read
Hi
I want to query database using SQLalchemy
Someone know why print(User.query.filter_by(username=next(iter(session))).first()) dosen`t work?
(this has been answered in #help-coconut)
Can someone take a look at my question at #help-grapes
Does anyone knows why this is happening? I have a account model and a account info model. When I iterate over all accounts, and try to render the account info as account.info it works, but when I try to render a column it doesnt render on the template
Using flask and sqlalchemy
anyone here familiar with linking a python project to an existing firebase project
@west lark Looks like its a list rather than a single object
So, I have a feature that adds a row of data every time someone uses it to a table in my PostreSQL database, but I want to make it so that each new added row is only kept there for 15 days and is then erased. How should I go about implementing it? Add a new "date_of_creation" column, include the day it was added to the database and have the bot loop through every single entry in that table every midnight and delete ones that have been added 15 days ago?
You could have it loop through say every hour and looks for ones that are to be deleted in less than 1 hour and schedule a task for it
Unless it doesnt have to be very accurate then just check evry hour and delete
Dont even have to check, could just be a query deleting on creation date conditions
cursor.execute("SELECT username FROM discordusers WHERE username=? GROUP BY username", (e[0])) pyodbc.Error: ('07002', '[07002] [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 2. (-3010) (SQLExecDirectW)')
i've been getting this erro
but it wasn't there before
I fixed it nvm
apperently someone changed a database column title
got me all confused
So i am using asyncpg. And i am working on a punishments feature. I need to save a datetime.datetime object into the db, how would i do this? I dont know what o put in the Table etc.
Like, when i create my table
@faint blade you could try and store the object as a string of bytes
That might work. Although i found another way to save it "CURRENT_TIMESTAMP"
The part in the table: StartTime TIMESTAMP,
Ok
TIMESTAMP datatype
Hey, I was told to ask my question here.
If I want to combine 35 CSVs that have somewhat different column names, what's the best way to do it?
I'm trying to do it with "usecols" from Pandas, but when there aren't column names that I'm specifying within a CSV, it spits an error.
Here's an example
'COL2',
'COL3',
'COL4',
'COL5',)
for f in os.listdir(os.getcwd()) if f.endswith('csv')]
combexample = pandas.concat(example, axis=1, join='inner').sort_index()```
So, some of the files might not have COL4 (it's technically the same info within the row, but the header name is different). How can I get it to combine properly?
I'd love any help I can get.
If it helps, there are 40 total files.
@deft badge can you just get all columns, and filter after you've got the data in the dataframe?
or if the columns are all in the same order, you can use numbers for usecols
So there are two separate blocks of data - the order of the columns (and some of the names) changes between the two, but within each block they're in the same order.
ok so what i'd do is probably break your list comprehension out into a loop, for one thing
just do a plain read_csv (without use_cols)
So something like this?
example = [pandas.read_csv(f, index_col=[0], parse_dates=[0], engine='python')
for f in os.listdir(os.getcwd()) if f.endswith('csv')]
like i said, i would not do this as a comprehension
Sorry, I know I'm being dense. I'm relatively new to this - apologies if I misunderstand you.
something like
example = []
for f in os.listdir...:
df = pandas.read_csv(f, index_col=[0], parse_dates=[0], engine='python')
if all(x in df.columns for x in ['COL2', 'COL3', 'COL4', 'COL5']):
df = df[['COL2', 'COL3', 'COL4', 'COL5']] # COL1 is index
elif: #another set of columns...
...
else:
raise Exception unknown csv format
example.append(df)```
So index_col is actually an empty column?
huh?
i'm not sure what you mean by that
you're specifying index_col as the first column
(is this always the first physical column? the situation gets hairier if it might not be)
it's still workable if it's not i think, but a little more complex
anyway, you can't select the index column with df[[...]] because it's always included
Okay so let me see if I'm understanding what you've written correctly
df[[...]] makes a new dataframe with a subset (and reordering) of the columns of the first dataframe
I think it's a fast operation because a dataframe is fundamentally a collection of column series, not rows
It's going to read all of the files in the working directory, and then go through them in descending order. For each file it opens, it will do a check on whether the named columns match in the order specified - if not, it will check for some second set of columns, and if it fails both of those it'll do some third thing (in this case, shoot out an error saying it's not one of the formats you specified)
Once that happens, I'll have a dataframe with all the data, though the columns won't be reordered properly yet, right?
the order of columns doesn't matter
you're defining the order you want them in, not the order the file has them in
Okay. That's awesome. It'll keep the row data from the columns properly and put them into the order I want?
(the check doesn't depend on the order at all, the df[[...]] defines the order of columns in the new dataframe)
yeah
Now, do I need to explicitly name every single column, or could I use this to select only the columns I actually need?
you can select only the ones you actually need
but
you have to rename the columns that mean the same things to be the same, for the concat to work
Okay - so should I run this to output two separate dataframes for the two different blocks? As it's written, I understand it to say that it'll only create one dataframe (example)
It wasn't clear to me if you needed two separate dataframes
I ultimately want one fully combined dataframe, where the columns that aren't listed in one another just get a NaN or 0 - that said, some of the names change and are actually the same thing
ok
for the names that change, you need to rename them using df['new name'] = df['old name']; del df['old name']
So if there was already a df['col1'], and I know that df['col2'] is the same and rename that one df['col1'], will it combine the two?
(df[old name].name = new name works, but doesn't do what you need for the concat to work - it sets the series internal idea of its name, whereas you need to set the name in the dataframe)
OK
...no
the renames are in the single file data frame
then, you'll have all of the columns named as col1 in those, and concat will pick them up and combine them
i.e. in the first file's dataframe you can rename col2 to col1, in the second you can rename col3 to col1, and in the third you can leave col1 alone, and it'll combine them all in concat to the big dataframe's col1
Okay, got it. So for the first code block you gave me (starting with example = [] ), does that create one mega-file with both blocks in it?
Okay, I see on that
well, it's creating the list that you still have to pass to pandas.concat to make the mega frame - i left that out because that part doesn't change
Again, apologies for being dense. I'm trying to understand what you're writing rather than just copy-pasting it and having no clue what's happening
Got it.
you can also do more fine grained comparisons than this, it'd help if i knew what your files actually looked like
like, if the main difference between the blocks is that the "foo" column is named "bar" in one of them
you can just do py if 'foo' not in df.columns: df['foo'] = df['bar']; del df['bar']
Should I just message you a head(1) from each block? The format is the same through both blocks, as I said
well does my last example get the point across?
the all() check was only really needed for if the format is a total black box
Yeah, that makes sense.
and if you don't need all the columns - if you do want to use all the columns and just have NAN if it's missing, then you can do the more targeted approach
Okay, let me try running some code first and get back with any problems. Thank you so, so much for the help you've given so far.
yeah no problem
lol fml this is the error I'm getting
File "<ipython-input-11-e65193353112>", line 15
raise Exception unknown csv format
^
SyntaxError: invalid syntax
it was pseudocode
i didn't feel like typing the parentheses and quotes, i figured you'd notice it
though really
Sorry, let me work this more. I wont come back till I've gotten something more substantively unworkable.
you don't necessarily need that section if you're going for just targeted specific column renames instead of the blanket "check if all of one set columns are present" thing
Okay.
Oh wow, it actually ran. Here's what I wrote, and I don't know if it is correct or stupid:
for f in os.listdir('C:\\Users\\baxte\\Documents\\Datasets\\house-office-expenditures-with-readme\\Detail'):
df = pandas.read_csv(f, index_col=[0], parse_dates=[0], engine='python')
if all(x in df.columns for x in ['ColA', 'ColB', 'ColC']):
df = df[[''ColA', 'ColB', 'ColC'']]
elif all(x in df.columns for x in ['ColD', 'ColE', 'ColF']):
df = df[['ColD', 'ColE', 'ColF']]
example.append(df)```
No errors, either
So now I've got a list of all the files, right?
Insofar as attempting to describe the dataframe was a no go. Told me it was a list. I assumed that example got the dataframe df by the append function.
Okay so I guess the question is really "should I concatenate now, or change the column names first?" - I'll try both, I suppose
you hae to change the column names to concatenate
it matches by column names, not position
Okay, yeah - the fact that it was still running the concat was worrying, haha
honestly
you could probably just use dataframe append instead
final_df = DataFrame()
for f...:
df1 = read_csv...
# rename columns if necessary
final_df.append(df1)```
that way you can print each file you ingest for some idea of progress, instead of the big expensive operation being the concat at the end that you have no idea how far it is in it
Okay, not understanding what you're suggesting there. Will each separate file within the directory be added to df1 with renamed columns until it's finished the loop?
Sorry, the pseudocode is hurting my comprehension a bit.
Hi, I have a data frame with len(df) == 19 and two pd.Series both with len(series) == 10, I've tried a bunch of different combinations of concat append, join, but can't get it right. I want to add the two series to the right side of the dataframe from df.index[0:11] and fill the rest( [df.index[10:]) with np.nan. Is there any way I can tackle this problem?
@cerulean widget try just adding the series to the dataframe?
like, this works: ```py
df = pd.DataFrame({'a':range(19), 'b':range(30, 49)})
c = pd.Series(range(50, 60))
d = pd.Series(range(60, 70))
df['c'] = c
df['d'] = d
if they all already have non-trivial indexes you might have to do something else
@quartz salmon df1 is a temp dataframe, you'd be adding them to final_df
but otherwise, yeah
sorry ... wasn't meant as pseudocode, more just "same as what you have"
Okay, so I created final_df1 and final_df2 for the two separate blocks, and the code ran. Once I've done that, can I concatenate the two final_df's separately and then modify the column names as needed to ultimately concatenate them together?
the point is to append to a dataframe instead of a list, to let you skip the concat step, and do the work one piece at a time instead of the whole concat thing at once
er
i was figuring just a single final_df
that you append both types of file into, after renaming the columns as necessary
since the point is to avoid the single massive monolithic concat at the end, which you said was taking a long time with no idea of progress
Oh, okay - so I should have a section in the elif block that renames the columns as necessary?
thank you for the response. so to give you guys some context, these are the two Series I am trying to append:
min = pd.Series([train[j].min() for j in list(info.index[0:10])])
max = pd.Series([train[j].max() for j in list(info.index[0:10])])
ok i feel like you ignored the part where i said e.g. like, if the main difference between the blocks is that the "foo" column is named "bar" in one of them py if 'foo' not in df.columns: df['foo'] = df['bar']; del df['bar']
i tried @patent glen 's method and I'm getting all nan
@cerulean widget when you create the series, pass info.index[0:10] as the second argument so they all have the same index
e.g.
example = []
for f in os.listdir('C:\Users\baxte\Documents\Datasets\house-office-expenditures-with-readme\Detail'):
df = pandas.read_csv(f, index_col=[0], parse_dates=[0], engine='python')
if all(x in df.columns for x in ['ColA', 'ColB', 'ColC']):
df = df[[''ColA', 'ColB', 'ColC'']]
elif all(x in df.columns for x in ['ColD', 'ColE', 'ColF']):
df = df[['ColD', 'ColE', 'ColF']]
if 'ColA' not in df.columns:
df['ColD'] = df['ColA'];
del df['ColD']
example.append(df)
i.e. pd.Series([train[j].min() for j in list(info.index[0:10])], info.index[0:10])
@deft badge er my point was to have that if/rename thing instead of the if/elif/df[[...]] thing (OOPS WRONG PING SORRY)
not inside the elif
hm..interesting
Thank you very much for the help! i was trying to figure this out for the past hour and a half..
still new to programming
Thank you @patent glen
also i maybe wouldn't call your series objects 'min' and 'max'
could get confused with the min and max functions
maybe something like min_series
oh right..i'll definitely be mindful of that
Okay, so I'm trying to run this code now - does this look right, @patent glen?
for f in os.listdir('directoryaddress(it's real in the code)'):
df = pandas.read_csv(f, index_col=[0], parse_dates=[0], engine='python')
if 'COLA' not in df.columns:
df['COLA'] = '0';
if 'COLB' not in df.columns:
df['COLB'] = '0';
if 'COLC' not in df.columns:
df['COLC'] = df['COLD'];
final_df.append(df)```
The 0's are on purpose, I just want to throw in blank/junk data where it's not there. Is it possible to do just "" for actual, blank data where the column is missing?
Realize that I didn't make a dataframe at the top - just a list. it should be final_df = pandas.DataFrame()
Got this fun error when I tried to describe it:
ValueError: Cannot describe a DataFrame without columns
I'm guessing that's because this new dataframe I just made has literally no column names. I'll try adding the final columns and see if that breaks it?
@quartz salmon if you just leave the columns out, the append should fill them in with NaN
The code I pasted up there ran and didn't spit out any errors, which suggests that it filled in, but yeah - no column names, so no ability to manipulate the data
DataFrame() itself works fine, just don't try to describe() it
Yeah, I just need to have the column names so I can do stuff like run basic stats on the numeric values etc.
after you add the first file it will have columns
like, add them before that if you want, but i don't see why you'd need to
or are you saying it does that at the end? idk why, append docs say "Columns not in this frame are added as new columns."
Once it's run the whole codeblock that I pasted, I still have no column names - I was under the assumption that this code block would take the files and their data, modify the column names where needed, and append it all to a giant dataframe with the corrected column names and all data
Obviously I'm misreading what you wrote above, and again I apologize for being dense. It's been ~10 hours of me trying to make this work at this point
I thought it would too, don't know why it isn't working as expected
So yeah, I'll try adding the column names at the top before the code runs - I'll come back with the results on that
oh wait, append doesn't mutate final_df lol
Wait what, so it doesn't actually add any data to it?
i'm an idiot, sorry
I'm obviously confused. I've definitely used append before to add data haha
it returns a new object
which is what i was trying to avoid by not using concat
try final_df = final_df.append(df)
but you might be better off going back to concat - measure how much time it takes both ways
anyway i need to go, be back later
Thank you so much! I'll keep trying to get this to work.
That actually fixed it into a real dataframe, you solved part of my issues (a huge part)
Thank you so, so much @patent glen - I'll keep it up and come here with any questions. You're a lifesaver.
ok i'm back btw
Okay, and yeah - I think I was being stupid
df['COLA'] = '0';```
This doesn't actually make COLA exist for the files in which it doesn't, right? My intent was to create COLA where it didn't, and fill it with 0s.
@patent glen in case you're off elsewhere
i think it does, but
you're filling it with a string 0, not number 0
if you don't bother with that it'll fill with NaN
Okay, so I don't even need to include that - it'll just fill NaN if I don't have an if statement for a column I know doesn't exist in some files
right
if you want another value you can do that though
df[name] = scalar creates a new series consisting of the value repeated over the dataframe's index
It's really not important one way or the other, so the less code I write the better
Okay, so yeah - I've got an empty dataframe according to print
print(final_df) returns
Empty DataFrame
Columns: []
Index: []
Fuuuuuudge
Yeah, I do. I'm trying a solution by adding the ultimate column names when calling final_df initially at the start of that code block. I'll give you an update in a second once its run
i don't think that's what it is
No, it isn't. Still empty, but it has some shiny new columns haha
And yes, I was still using the append.
maybe go back to building a list and using concat
right but including final_df = ...append, not just the append call
since the problem is append returns the new dataframe
... yeah, I didn't have that part
you had it at one point i think - maybe got lost in editing
Yeah, it did. Still a problem, though, even with that being the case
specifically when I try to do something like final_df(['COLA'].sum() it gives me this error:
TypeError: 'DataFrame' object is not callable
you've got a stray parenthesis
[and probably another one elsewhere]
final_df['COLA'].sum(), no final_df(
So I now realize that my code is actually only capturing the last file. God help me
I think that's because I put the append function outside of the for loop, so the for loop replaced itself every time
whats the best module to use a mysql database>?
@torn sphinx depends on your requirements and your definition of βbestβ, iirc pymysql is thebest maintained one
@oblique horizon dont ask to ask
!t ask
Asking good questions will yield a much higher chance of a quick response:
β’ Don't ask to ask your question, just go ahead and tell us your problem.
β’ Try to solve the problem on your own first, we're not going to write code for you.
β’ Show us the code you've tried and any errors or unexpected results it's giving
β’ Keep your patience while we're helping you.
You can find a much more detailed explanation on our website.
I'm sorry man, but I've basically scraped google for anything and I'm at a loss as to what to ask
I guess does anyone know of an up-to-date or well-supported/documented library that integrates mongo into django
because the libraries I found are either deprecated or undocumented
whats a good place to start when learning about data bases with python?
a nice easy one is SQLite because it's in the standard library (import sqlite3). try to think of a scenario where a database could be used. perhaps a bank application: you've got to store information about people (name, age, address, etc), who each have an account, which stores their balance. maybe allow for people to take out loans, and store those too. you could simply make a text application that allows you to work with the database. @short fjord
Ok, cool thats actually what ive been working with
basically, i feel like a hands-on approach is important. banking is just an example, but if there's something in particular that you're interested in, go for that instead.
Banking sounds fun actually, ill give it a shot. thanks!
no problem!
python documentation for the sqlite3 module specifically: https://docs.python.org/3/library/sqlite3.html
in-depth documentation for the SQL queries you can execute with that module: https://www.sqlite.org/docs.html
perfect, thanks
$hello
!hello
!hello
oops wrong channel XD
meant to do that in my server
congratulations! :D
haha
@short fjord one hint on banking, dont use floats. use fixed point numbers
dont want to lose 0.0001 of a cent
Ok, thanks for the tip
Anyone here?
Im pretty new and am having an issue understanding pycharm. I have a venv and my script.py which writes to my database in my project folder. If I want to have the script run do i run it straight from just the project folder or do i have to go into the venv?
basically when would i go into the venv
figured it out nevermind
cursor.execute("SELECT discord_id FROM discordusers WHERE discord_id=? GROUP BY discord_id", (ctx.message.author.id)) pyodbc.Error: ('HYC00', '[HYC00] [Microsoft][ODBC Microsoft Access Driver]Optional feature not implemented (106) (SQLBindParameter)')
im getting this error
but i have no idea what it means
sounds like some form of paywall based on the microsoft
wait no
you need a trailing comma
to make the parameter actually a tuple
cursor.execute("SELECT discord_id FROM discordusers WHERE discord_id=? GROUP BY discord_id", (ctx.message.author.id,))
Continuing what you were saying @ionic pecan
The thing is, I was looking for a db for my bot, and everyone suggest using postgres
I just want a database that's easy to use/understand, while still working on a larger scale
postgres is the correct choice then
once you get past the initial setup stuff it's very straightforward
and once you understood that once it sticks
which resources are you using?
Wdym?
for learning postgres
The wiki and http://www.postgresqltutorial.com/
Learn PostgreSQL quickly through a practical PostgreSQL tutorial designed for database administrators and application developers.
http://www.postgresqltutorial.com/postgresql-administration/ seems to be what you want
Think on, I have 0 experience outside of using an sqlite db a few times
This is gonna be fun..
I got this far, now nothing makes sense
i wouldn't recommend using a gui for just figuring the base structure out
Then what would you suggest? I have 0 clue how to do anything with postgres
the CLI
Well, this is gonna be -very- fun
And it's just the beta build for my pc
I still gotta do it all again for my server
Is there not a way to view the columns, rows and tables using a gui? @ionic pecan
prett ysure there is
Welp, time to find that thing
so you don't have the table
where did you pick that up?
you're missing semicolons
wow π
yeah ikr
i realy need to start learning more python π
Can someone please tell me a quick solution to run a .sql file without installing apache and phpmyadmin etc
Is a connection absolutely necessary to run the file? Why can't we just execute the statements?
you can ?
create a database from the mysql REPL (using CREATE DATABASE your_db, and then you can use ```
mysql -u your_username -p your_db < your_script.sql
Hi, is someone familiar with sqlite? If so can you help me understand why I get a syntax error while running this command?
c.execute("INSERT INTO "+table+"(date,price) VALUES(?,?) ON CONFLICT(date) DO UPDATE SET price=excluded.price",(date,price))
(both table, date and price are variable defined in the python code and date is a primary int key for the table)
does it give you any more detail on the syntax error
sqlite3.OperationalError: near "ON": syntax error it's all it says
The phrase "ON CONFLICT" is also part of UPSERT, which is an extension to INSERT added in version 3.24.0 (2018-06-04).
i get the error too, i'm on version 3.22
what version of sqlite are you on
I copied the command from the documentation on upsert and just modified what was needed for my case
ehm, how do I check? for sure 3.xx but not sure which one
sqlite3.sqlite_version
anyway your syntax looks fine to me, it's probably just not supported on your version
is sqlite the best way to handle databases in python? I'm pretty new to them and that's the first that I found. I don't need to handle a very large database
I'm on version 3.21 of sqlite apparently, wouldn't come up earlier because I was using the version included in python and hadn't installed it separately
you can get the version in python with sqlite3.sqlite_version
that may or may not be the same as your standalone sqlite
anyway i wouldn't say there's a best way necessarily, sqlite has the advantage of not requiring a server setup
yeah was asking just in case there was an option that was "mainstream" and largely preferred over the others, maybe will try to look for some other ways
I have a python file that runs correctly. When I create a exe with pyinstaller and I try to run my program, it works only the first time (second times I get a database error). The code without compiling works fine
This is all the database loading: https://paste.pydis.com/ujiriwuxob.py
All the code: https://paste.pydis.com/bezufokawa.py
you need to show us the error you're getting
I have a DataFrame with column names range(0, 28). I have a variable column: column =[RANK, TEAM, GP, W, L, WIN_PERC, MIN, PTS, FGM, FGA, FG_PERC, THREE_PM, THREE_PA, THREE_P_PERC, FTM, FTA, FT_PERC, OREB, DREB, REB, AST, TOV, STL, BLK, BLKA, PF, PFD, PLUS_MINUS]. How can I replace the numbered column names with the values in the columns?
Pandas dataframe?
df.columns = column
should do that.
i had a quick question, is MongoDB blocking?
Question regarding aiomysql
This is how I open a connection and a cursor:
async with self.pool.acquire() as conn:
async with conn.cursor() as cur:
await cur.execute(query, values)
await conn.commit()
But, should I close the cursor or connection or both or none after using it? π€
await cur.close()
conn.close()
Opening them as context managers should handle the teardown and closing automatically when you exist the scope of the context manager (the async with part)
if i want to download mysql, whichone do i download?
does community edition work or i need to pay for it
@torn sphinx Don't
hi
MySQL is the worst SQL
rly?
Yeah
im trying to get this provably fair system thingy
and the guide wants me to use mySQL
And is the guide god of all SQL flavours
I suggest you use and learn PostgreSQL and if this is for your bot, use asyncpg as your library
o
Saying Mysql is the worst sql doesn't really help anyone here
What are you using the database for?
I understand a usecase
And
Unless there's no other option
MySQL isn't the way to go
is @indigo mason here
Yes
hey is postgresql good
There ya go
it is?
can someone help me understand what's wrong with how im inserting things into this db?
+-------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| title | text | NO | | NULL | |
| body | text | NO | | NULL | |
+-------+---------+------+-----+---------+----------------+
and im inserting using
INSERT INTO post ("test post", "my first test post");
which gives a syntax error
SQL? Where your values are now the column names should be, the values go after "VALUES". See this for instance: https://www.w3schools.com/sql/sql_insert.asp
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
I'm using
query = "SELECT warnings FROM warnings WHERE userid = $1;"
row = await self.bot.db.fetchrow(query, ctx.author.id)
and it returns <Record warnings=0>, which is the value set. But how can I just get it to show 0?
row.warnings?
File "C:\Users\Paws\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\ext\commands\core.py", line 61, in wrapped
ret = await coro(*args, **kwargs)
File "C:\Users\Paws\Desktop\buibot\cogs\mod.py", line 56, in warns
await ctx.send(f"You currently have **{row.warnings}** warnings.")
AttributeError: 'asyncpg.Record' object has no attribute 'warnings'
weird
Looking to chat with someone about imdbpy. In accessing a s3 database file. spicifically lines 54 - 105 of https://paste.pound-python.org/show/35r0Yg0KRK215bXMpHlK/ this is me just playing around learning.
nvm, i got some help. thank you anyway.
doesnt sound like something related to databases to me
also we donβt exclude people by age here
!t ask
Asking good questions will yield a much higher chance of a quick response:
β’ Don't ask to ask your question, just go ahead and tell us your problem.
β’ Try to solve the problem on your own first, we're not going to write code for you.
β’ Show us the code you've tried and any errors or unexpected results it's giving
β’ Keep your patience while we're helping you.
You can find a much more detailed explanation on our website.
Oh so if i ask a good question it will add a much higher chance to an iterable?
Cool x3
!rules
The rules and guidelines that apply to this community can be found on our rules page. We expect all members of the community to have read and understood these.
bot stuff --> #bot-commands
I have no clue where this question belongs but:
Heroku keeps resetting my database to the state it was uploaded in, help?
I have an sqlite database implemented through python for my discord bot
Heroku keeps restarting the database to how it was when it was uploaded (value wise)
Why, and how do I fix this?
One of the reasons heroku is not suited for a discord bot. Heroku essentially clones the environment and destroy it at each request (or something in that manner). SQL files should be stored else where or use a heroku database. They have strict rules that you cannot expect files saved to not be frequently wiped
( Source: https://stackoverflow.com/a/13552761 & https://www.reddit.com/r/Heroku/comments/82c8sr/prevent_heroku_from_overwriting_sqlite_db_on/ )
I haven't used anything other than a raspberry pi, but digital ocean has been recommended
i use digitalocean, it's pretty good
I'm using postgresql and asyncpg, and can't work out how to get information from a row and put it into a message. I can get a single random row, but not the info from the columns.
Asking good questions will yield a much higher chance of a quick response:
β’ Don't ask to ask your question, just go ahead and tell us your problem.
β’ Try to solve the problem on your own first, we're not going to write code for you.
β’ Show us the code you've tried and any errors or unexpected results it's giving
β’ Keep your patience while we're helping you.
You can find a much more detailed explanation on our website.
query = await db.execute("SELECT * FROM sketchdaily ORDER BY RANDOM() LIMIT 1;")
row = await db.fetch(query)
print('True, sending webhook message')
webhook = DiscordWebhook(url=f'{config.webhookurl}', content=f"{row['idea']}")
webhook.execute()
With the error
Traceback (most recent call last):
File "index.py", line 33, in <module>
loop.run_until_complete(run())
File "C:\Users\Paws\AppData\Local\Programs\Python\Python37-32\lib\asyncio\base_events.py", line 573, in run_until_complete
return future.result()
File "index.py", line 25, in run
webhook = DiscordWebhook(url=f'{config.webhookurl}', content=f"{row['idea']}")
TypeError: list indices must be integers or slices, not str
fetch probably returns a list of rows, not a single row
you're probably looking for something like fetchone
Traceback (most recent call last):
File "index.py", line 33, in <module>
loop.run_until_complete(run())
File "C:\Users\Paws\AppData\Local\Programs\Python\Python37-32\lib\asyncio\base_events.py", line 573, in run_until_complete
return future.result()
File "index.py", line 23, in run
row = await db.fetchone(query)
AttributeError: 'Pool' object has no attribute 'fetchone'
Guys. I'm facing a bug that is beyond my comprehension/knowledge
I have a database
linked to my discord bot
I use a table as a cache for the bot
every 15min
I want to reset the tables to write in it again
Thus
I do this query
TRUNCATE TABLE cmc_coins;
then I write again in the table
but it looks like
there is some bug between the moment I truncate
and the moment I Insert Into
and the try except gives me nothing
moreover. The bot silently crash and disconnect. Event though it's still running in the IDE
some Side Infos : Postgres 9.6 DB hosted on Google Cloud. Python 3.7 using pipenv. Psycopg2 as lib for DB queries
Please help me π¦
how do you use your db? through the ORM?
ORM ?
Object-relational mapping (ORM, O/RM, and O/R mapping tool) in computer science is a programming technique for converting data between incompatible type systems using object-oriented programming languages. This creates, in effect, a "virtual object database" that can be used ...
e.g SQLAlchemy
how do you execute TRUNCATE and INSERT using the python, which library or whatsoever
ok
and I defined the connection and cursor in the attributes of the class
and what exactly your bug is?
TRUNCATE is not executed?
and the table is wiped or not?
I don't know... When I do a SELECT * FROM cmc_coins;
the query never ends
Here is the Truncating code part
but you could manually check the DB
I want to DB to be wiped every 15min a few seconds before refilling them (thus the 895sec timer)
I have Datagrip open to check the DB manually
Why use a database for that? Is the cache huge?
Why wipe it then?
Cant you update the values?
I fail to see the need tp wrote 1500 rows every 15 min.
that I didn't think of this ...
To write *
Im sure it might currently
we don't you keep in memory
Im just trying to understand what it's doing.
Here is he kind of data i'm storing
the api is rate limited
thus the need to cache
and how do you use it then?
I select things in there when I need them
well I would keep that in memory
if it's 1500 rows only
but still your question is why nothing is happening
None of the prints trigger?
How are you calling the method then
And are your other tasks running?
yessir
there are 3 tasks
1 tasks to wipe 2 tables (the one we are talking about)
another task to fill the table cmc_coins
and the last task to fill the table cmc_global
the task to wipe runs every 895 seconds
Is the bot responsive?
What does the other tasks look like
Sounds to me that you're blocking the bot then.
the other task are basically a big Insert Into
sounds like you have a blocking issues there.
Also are you using asyncpg
no
psycopg2
and I do indeed havea blocking issue
the problem is that I can't find it precisely
I'd try asyncpg then and see if that fixes some of them
Pycopg2 is blocking though