반응형
파이썬을 이용한 샘플 코드 조각 생성소스
# -*- coding:utf-8 -*-
"""
INSERT, SELECT, UPDATE, DELETE Sample Query
Column is up to you, but value is only Camel
author : Jeffrey Oh
"""
# table_name = "테이블명"
# c = ["컬럼명", "컬럼명", "...", "컬럼명"]
# sample
table_name = "adm_member"
c = ["seq", "user_id", "user_pw", "user_pw_enc", "name", "tel", "phone", "email", "zipCode", "addr1", "addr2", "remoteIp"]
insert = "INSERT INTO "+table_name+" ("
i1 = ") VALUES ("
i2 = ")"
cc = ""
s = ""
size = len(c)
for i in range(0, size) :
if(i + 1 < size) :
cc += c[i] + ", "
else :
cc += c[i]
cc += i1
for i in range(0, len(c)) :
ts = ""
if(i + 1 < len(c)) :
if(c[i].find('_') != -1) :
ts = c[i][:(c[i].find('_'))] + c[i][(c[i].find('_'))+1:].capitalize()
if(c[i].count('_') > 1) :
for j in range(0, c[i].count('_')-1) :
ts = ts[:(ts.find('_'))] + ts[(ts.find('_'))+1:].capitalize()
s += "#{" + ts + "}, "
else :
s += "#{" + c[i] + "}, "
else :
if(c[i].find('_') != -1) :
ts = c[i][:(c[i].find('_'))] + c[i][(c[i].find('_'))+1:].capitalize()
if(c[i].count('_') > 1) :
for j in range(0, c[i].count('_')-1) :
ts = ts[:(ts.find('_'))] + ts[(ts.find('_'))+1:].capitalize()
s += "#{" + ts + "}, "
else :
s += "#{" + c[i] + "}"
cc = cc + s + i2
print(insert+cc+"\n")
delete = "DELETE FROM " + table_name + " WHERE " + c[0]
if(c[0].find('_') != -1):
delete += "=#{" + c[0][:(c[0].find('_'))] + c[0][(c[0].find('_'))+1:].capitalize() + "}"
else :
delete += "=#{" + c[0] + "}"
print(delete+"\n")
update = "UPDATE "+table_name+" SET "
cc = ""
s = ""
for i in range(0, len(c)) :
ts = ""
if(i + 1 < len(c)) :
if(c[i].find('_') != -1) :
ts = c[i][:(c[i].find('_'))] + c[i][(c[i].find('_'))+1:].capitalize()
if(c[i].count('_') > 1) :
for j in range(0, c[i].count('_')-1) :
ts = ts[:(ts.find('_'))] + ts[(ts.find('_'))+1:].capitalize()
s += c[i] + "=#{" + ts + "}, "
else :
s += c[i] + "=#{" + c[i] + "}, "
else :
if(c[i].find('_') != -1) :
ts = c[i][:(c[i].find('_'))] + c[i][(c[i].find('_'))+1:].capitalize()
if(c[i].count('_') > 1) :
for j in range(0, c[i].count('_')-1) :
ts = ts[:(ts.find('_'))] + ts[(ts.find('_'))+1:].capitalize()
s += c[i] + "=#{" + ts + "}, "
else :
s += c[i] + "=#{" + c[i] + "}"
cc += s + " WHERE " + c[0]
if(c[0].find('_') != -1):
cc += "=#{" + c[0][:(c[0].find('_'))] + c[0][(c[0].find('_'))+1:].capitalize() + "}"
else :
cc += "=#{" + c[0] + "}"
print(update+cc+"\n")
select = "SELECT "
cc = ""
for i in range(0, size) :
if(i + 1 < size) :
cc += c[i] + ", "
else :
cc += c[i]
cc += " FROM " +table_name+ " WHERE " + c[0] + "=#{" + c[0] + "}"
print(select+cc)
INSERT INTO adm_member (seq, user_id, user_pw, user_pw_enc, name, tel, phone, email, zipCode, addr1, addr2, remoteIp) VALUES (#{seq}, #{userId}, #{userPw}, #{userPwEnc}, #{name}, #{tel}, #{phone}, #{email}, #{zipCode}, #{addr1}, #{addr2}, #{remoteIp})
DELETE FROM adm_member WHERE seq=#{seq}
UPDATE adm_member SET seq=#{seq}, user_id=#{userId}, user_pw=#{userPw}, user_pw_enc=#{userPwEnc}, name=#{name}, tel=#{tel}, phone=#{phone}, email=#{email}, zipCode=#{zipCode}, addr1=#{addr1}, addr2=#{addr2}, remoteIp=#{remoteIp} WHERE seq=#{seq}
SELECT seq, user_id, user_pw, user_pw_enc, name, tel, phone, email, zipCode, addr1, addr2, remoteIp FROM adm_member WHERE seq=#{seq}
반응형
'Backend > Python' 카테고리의 다른 글
IE && Chrome browsermobproxy setting (0) | 2020.05.21 |
---|---|
WebDriver & Selenium 모든 팝업창 닫기 (1) | 2020.05.01 |
ftp 업로드 후 파일 사이즈 0 (ftp upload file size 0) (2) | 2019.12.07 |
라이브러리를 이용하여 엑셀 데이터 읽기 (0) | 2019.12.05 |
유니코드 인코딩 쉽게 (0) | 2019.11.21 |