コード例 #1
0
ファイル: dbsql.py プロジェクト: kane-chen/headFirstPython
    cursor = conn.cursor() ;
    
    cursor.execute("insert into athletes(name,birthday)values(?,?)",(athlete.name,athlete.birth));
    conn.commit() ;
    conn.close() ;
    
def insert_detail(db_name,athlete,id):  # @ReservedAssignment
    conn = sqlite3.connect(db_name);
    cursor = conn.cursor() ;
    
    cursor.execute("insert into athletes_datas(athlete_id,value)values(?,?)",(id,str(athlete.top)));
    conn.commit() ;
    conn.close() ;

james = 'james2.txt' ;
athlete = get_data_in_file(james) ;
insert_data(db_name,athlete);
insert_detail(db_name,athlete,1);



def select_data(db_name,id):  # @ReservedAssignment
    conn = sqlite3.connect(db_name) ;
    cursor = conn.cursor() ;
    
    results = cursor.execute("select name,birthday,value from athletes ath left join athletes_datas det on ath.id = det.athlete_id where ath.id = ? ",(id,)) ;
    (name,birth,value) = results.fetchone();
#     print(name);
#     print(birth);
#     print(value);
    return Athlete(name,birth,value);
コード例 #2
0
'''
Created on 2014-1-21
@author: Administrator
'''
#import class/method
from athelets import get_data_filelist, get_data_in_file

james = get_data_in_file('james2.txt')
print(james.name);
print(get_data_filelist(['james2.txt']));