Skip to content

Updated Data Base Connector #1

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 8 additions & 15 deletions Database_python_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,19 @@
import os
from sqlite3 import Error

# Used to create connection with Database file
def create_connection(Education):
conn = None
try:
conn = sqlite3.connect(Education)
except Error as e:
print(e)

return conn

# col_name
# Used to Select the Column Names from table
def select_task(conn,table_name,col_name,where_clause):
cur = conn.cursor()
#new string
str_query = ""

str_query = str_query + "SELECT "
str_query = "SELECT "
print("After adding select keyword ",str_query)

#string for all the relevent columns of the table:
Expand Down Expand Up @@ -55,22 +52,17 @@ def delete_task(conn,table_name,where_clause):
str_query = str_query + "DELETE FROM " + table_name + " WHERE "+ where_clause
else:
str_query = str_query + "DELETE FROM " + table_name

str_query="Select * FROM "+table_name

print( " Now Delete Query is ",str_query)

cur.execute(str_query)

rows = cur.fetchall()

for row in rows:
print(row)

# update tb set c1 = c1_val , c2 = c2_val WHERE c_name = c_name_value
def update_task(conn,table_name,col_name,data,where_clause):
cur = conn.cursor()
str_query = ""
str_query = str_query + "update "+ table_name+ " set "
str_query = "update "+ table_name+ " set "

for i in range(len(col_name)):
str_query = str_query + col_name[i] + " = '"+ data[i] + "'"
Expand All @@ -79,7 +71,8 @@ def update_task(conn,table_name,col_name,data,where_clause):

if where_clause != "":
str_query = str_query + " WHERE "+ where_clause
#str = "update Subject set branch='computer science' where subject_id = 3"

#str = "update Subject set branch='computer science' where subject_id = 3"
print( " Now Update Query is ",str_query)

cur.execute(str_query)
Expand Down Expand Up @@ -115,4 +108,4 @@ def main():


if __name__ == '__main__':
main()
main()