Example #1
0
def insert_2():
    conn = getConn()
    cur = conn.cursor()
    ins_sq1 = 'insert into test values(?,?,?,?)'  # 동적쿼리
    cur.execute(ins_sq1, ('김철수', 55, 66, 77))  #반드시 튜플형태로
    conn.commit()
    conn.close()
Example #2
0
def insert_1():
    conn = getConn()
    cur = conn.cursor()
    cur.execute('''
        insert into test values('홀길동',60,70,80)
    ''')
    conn.commit()
    conn.close()
Example #3
0
def update_1(n_name, o_name):
    conn = getConn()
    cur = conn.cursor()
    upt_sql = 'update test set name=? where name=?'
    cur.execute(upt_sql,(n_name, o_name))

    conn.commit()
    conn.close()
Example #4
0
def delete_1(del_name):
    conn = getConn()
    cur = conn.cursor()
    del_sql = 'delete from test where kor<=?'
    cur.execute(del_sql,(del_name,))

    conn.commit()
    conn.close()
Example #5
0
class db:
    conn = getConn('C:/Users/bit/Desktop/새 폴더/phon.db')
    cur = conn.cursor()
    def createtable(self):
        db.cur.execute('create table tel(name text, no text)')
    def inserttable(self,name,no):09
        self.ist_sql = 'insert into tel values(?,?)'
        db.cur.execute(self.ist_sql, (name, no))
Example #6
0
def select_2(name):
    conn = getConn()
    cur = conn.cursor()
    cur.execute('select * from test where name=?',(name,))
    rs = cur.fetchmany(1)  # 받아올거다 한개만
    for i in rs:
        print(i)

    conn.close()
Example #7
0
def insert_3():
    conn = getConn()
    cur = conn.cursor()
    li = [('이영자', 77, 88, 99), ('한의원', 78, 45, 11), ('커피', 11, 22, 33)]
    ins_sq1 = 'insert into test values(?,?,?,?)'  # 동적쿼리
    cur.executemany(ins_sq1, li)  #리스트 내부구조는 튜플
    cur.execute(ins_sq1, ('김철수', 55, 66, 77))  #반드시 튜플형태로
    conn.commit()
    conn.close()
Example #8
0
def create_table():
    conn = getConn() #DB와 접속 정보
    cur = conn.cursor() #DB를 보는 포인터
    cur.execute('''
        create table test(name text,
        kor int,
        eng int,
        mat int)
    ''')
    conn.commit() # 데이터베이스의 변경사항 확정
    conn.close() #닫아준다