Hack Bulgaria
github.com/HackBulgaria
-- here's how we can put comments in our SQL queries
SELECT id, name, password -- we're selecting all the passwords from the database
FROM users
WHERE age > 20; -- for the users older that 20
We'll see why is this important later...
BEGIN TRANSACTION;
...queries
COMMIT; / ROLLBACK;
A socket connection between your program and the DBMS
import sqlite3
connection = sqlite3.connect('example.db')
cursor = connection.cursor()
# Create table
cursor.execute(
'''
CREATE TABLE stocks
(date text, trans text, symbol text, qty real, price real);
'''
)
# Insert a row of data
cursor.execute("INSERT INTO stocks VALUES ('2006-01-05','BUY','RHAT',100,35.14);")
# Save (commit) the changes
connection.commit()
# We can also close the connection if we are done with it.
# Just be sure any changes have been committed or they will be lost.
connection.close()
import sqlite3
connection = sqlite3.connect('example.db')
cursor = connection.cursor()
# Create table
cursor.execute(
'''
CREATE TABLE stocks
(date text, trans text, symbol text, qty real, price real);
'''
)
# Insert a row of data
cursor.execute("INSERT INTO stocks VALUES ('2006-01-05','BUY','RHAT',100,35.14);")
# Save (commit) the changes
connection.commit()
# We can also close the connection if we are done with it.
# Just be sure any changes have been committed or they will be lost.
connection.close()
import sqlite3
connection = sqlite3.connect('example.db')
cursor = connection.cursor()
# Create table
cursor.execute(
'''
CREATE TABLE stocks
(date text, trans text, symbol text, qty real, price real);
'''
)
# Insert a row of data
cursor.execute("INSERT INTO stocks VALUES ('2006-01-05','BUY','RHAT',100,35.14);")
# Save (commit) the changes
connection.commit()
# We can also close the connection if we are done with it.
# Just be sure any changes have been committed or they will be lost.
connection.close()
import sqlite3
connection = sqlite3.connect('example.db')
cursor = connection.cursor()
# Create table
cursor.execute(
'''
CREATE TABLE stocks
(date text, trans text, symbol text, qty real, price real);
'''
)
# Insert a row of data
cursor.execute("INSERT INTO stocks VALUES ('2006-01-05','BUY','RHAT',100,35.14);")
# Save (commit) the changes
connection.commit()
# We can also close the connection if we are done with it.
# Just be sure any changes have been committed or they will be lost.
connection.close()
import sqlite3
connection = sqlite3.connect('example.db')
cursor = connection.cursor()
# Create table
cursor.execute(
'''
CREATE TABLE stocks
(date text, trans text, symbol text, qty real, price real);
'''
)
# Insert a row of data
cursor.execute("INSERT INTO stocks VALUES ('2006-01-05','BUY','RHAT',100,35.14);")
# Save (commit) the changes
connection.commit()
# We can also close the connection if we are done with it.
# Just be sure any changes have been committed or they will be lost.
connection.close()
import sqlite3
connection = sqlite3.connect('example.db')
cursor = connection.cursor()
# Create table
cursor.execute(
'''
CREATE TABLE stocks
(date text, trans text, symbol text, qty real, price real);
'''
)
# Insert a row of data
cursor.execute("INSERT INTO stocks VALUES ('2006-01-05','BUY','RHAT',100,35.14);")
# Save (commit) the changes
connection.commit()
# We can also close the connection if we are done with it.
# Just be sure any changes have been committed or they will be lost.
connection.close()
import sqlite3
connection = sqlite3.connect('example.db')
cursor = connection.cursor()
# Create table
cursor.execute(
'''
CREATE TABLE stocks
(date text, trans text, symbol text, qty real, price real);
'''
)
# Insert a row of data
cursor.execute("INSERT INTO stocks VALUES ('2006-01-05','BUY','RHAT',100,35.14);")
# Save (commit) the changes
connection.commit()
# We can also close the connection if we are done with it.
# Just be sure any changes have been committed or they will be lost.
connection.close()
Fetch Data
import sqlite3
connection = sqlite3.connect('example.db')
cursor = connection.cursor()
cursor.execute(
"""
CREATE TABLE users
(id integer primary key autoincrement, full_name varchar(100))
"""
)
cursor.execute(
"""
INSERT INTO users VALUES (1, 'ivo');
"""
)
cursor.execute("SELECT id, full_name FROM users;")
users_data = cursor.fetchall()
# Save (commit) the changes
connection.commit()
# We can also close the connection if we are done with it.
# Just be sure any changes have been committed or they will be lost.
connection.close()
some_var = input()
update_sql = "SELECT * WHERE username = " + some_var
cursor.executescript(update_sql)
Must watch - https://youtu.be/_jKylhJtPmI
Algorithms:
Â
- MD5
- SHA128
- SHA256
- ...
Â
Must watch - https://youtu.be/8ZtInClXe1Q
By Hack Bulgaria