From 7f91b5819c8e05c8304d60e0e5eb0649a43bb65d Mon Sep 17 00:00:00 2001 From: Marius Sandu-Popa Date: Fri, 23 Oct 2009 12:25:45 +0300 Subject: [PATCH] bd --- auto/script | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100755 auto/script diff --git a/auto/script b/auto/script new file mode 100755 index 0000000..11fae4a --- /dev/null +++ b/auto/script @@ -0,0 +1,80 @@ +#!/usr/bin/env python +from sqlite3 import * + +conn = connect('p2p-next.db') +curs = conn.cursor() + +curs.execute("pragma foreign_keys = ON;") +curs.execute('drop table if exists status_messages') +curs.execute('drop table if exists verbose_messages') +curs.execute('drop table if exists client_session') +curs.execute('drop table if exists btclients') +curs.execute('drop table if exists swarms') + +curs.execute("""create table swarms( + id integer primary key autoincrement, + torrent text, + filesize integer, + purpose text, + source text check(source in ('local', 'URL')) + )""") + +curs.execute('''create table btclients( + id integer primary key autoincrement, + name text, + language text, + dht integer check(dht between 0 and 1), + streaming integer check(streaming between 0 and 1) + )''') + +curs.execute('''create table client_session( + id integer primary key autoincrement, + swarm_id integer references swarms(id), + client_id integer references btclients(id), + system_os text, + system_os_version text, + system_ram integer, + system_cpu integer, + public_ip text, + public_port integer, + ds_limit integer, + us_limit integer, + start_time date + )''') + +curs.execute('''create table status_messages ( + cs_id integer references client_session(id), + timestamp date, + peer_num integer, + dht integer, + download_speed integer, + upload_speed integer, + download_size integer, + upload_size integer, + eta date + )''') + +curs.execute('''create table verbose_messages ( + cs_id integer references client_session(id), + timestamp date, + peer_ip integer, + peer_port integer check(peer_port between 1 and 65535), + message_type integer, + _index integer, + begin integer, + length integer, + listen_port integer check(listen_port between 1 and 65535) + )''') + +for t in [('1', 'mumu', '1024', 'ceva', 'URL'), + ('2', 'gugu', '1024', 'ceva', 'URL'), + ('3', 'gaga', '1024', 'ceva', 'URL'), + ]: + curs.execute('insert into swarms values (?,?,?,?,?)', t) +conn.commit() + +curs.execute('select * from swarms') +for row in curs: + print row + +conn.close() \ No newline at end of file -- 2.20.1