|
1 | | -#!/usr/bin/env python |
2 | | - |
3 | | -""" |
4 | | -$Id$ |
5 | | -
|
6 | | -Copyright (c) 2006-2010 sqlmap developers (http://sqlmap.sourceforge.net/) |
7 | | -See the file 'doc/COPYING' for copying permission |
8 | | -""" |
9 | | - |
10 | | -from lib.core.exception import sqlmapMissingDependence |
11 | | -from lib.core.exception import sqlmapValueException |
12 | | - |
13 | | -class Replication: |
14 | | - """ |
15 | | - This class holds all methods/classes used for database |
16 | | - replication purposes. |
17 | | - """ |
18 | | - |
19 | | - def __init__(self, dbpath): |
20 | | - try: |
21 | | - import sqlite3 |
22 | | - except ImportError, _: |
23 | | - errMsg = "missing module 'sqlite3' needed by --replicate switch" |
24 | | - raise sqlmapMissingDependence, errMsg |
25 | | - |
26 | | - self.dbpath = dbpath |
27 | | - self.connection = sqlite3.connect(dbpath) |
28 | | - self.connection.isolation_level = None |
29 | | - self.cursor = self.connection.cursor() |
30 | | - |
31 | | - class DataType: |
32 | | - """ |
33 | | - Using this class we define auxiliary objects |
34 | | - used for representing sqlite data types. |
35 | | - """ |
36 | | - |
37 | | - def __init__(self, name): |
38 | | - self.name = name |
39 | | - |
40 | | - def __str__(self): |
41 | | - return self.name |
42 | | - |
43 | | - def __repr__(self): |
44 | | - return "<DataType: %s>" % self |
45 | | - |
46 | | - class Table: |
47 | | - """ |
48 | | - This class defines methods used to manipulate table objects. |
49 | | - """ |
50 | | - |
51 | | - def __init__(self, parent, name, columns=None, create=True, typeless=False): |
52 | | - self.parent = parent |
53 | | - self.name = name |
54 | | - self.columns = columns |
55 | | - if create: |
56 | | - self.parent.cursor.execute('DROP TABLE IF EXISTS %s' % self.name) |
57 | | - if not typeless: |
58 | | - self.parent.cursor.execute('CREATE TABLE %s (%s)' % (self.name, ','.join('%s %s' % (colname, coltype) for colname, coltype in self.columns))) |
59 | | - else: |
60 | | - self.parent.cursor.execute('CREATE TABLE %s (%s)' % (self.name, ','.join(colname for colname in self.columns))) |
61 | | - |
62 | | - def insert(self, values): |
63 | | - """ |
64 | | - This function is used for inserting row(s) into current table. |
65 | | - """ |
66 | | - if len(values) == len(self.columns): |
67 | | - self.parent.cursor.execute('INSERT INTO %s VALUES (%s)' % (self.name, ','.join(['?']*len(values))), values) |
68 | | - else: |
69 | | - errMsg = "wrong number of columns used in replicating insert" |
70 | | - raise sqlmapValueException, errMsg |
71 | | - |
72 | | - def select(self, condition=None): |
73 | | - """ |
74 | | - This function is used for selecting row(s) from current table. |
75 | | - """ |
76 | | - stmt = 'SELECT * FROM %s' % self.name |
77 | | - if condition: |
78 | | - stmt += 'WHERE %s' % condition |
79 | | - return self.parent.cursor.execute(stmt) |
80 | | - |
81 | | - def createTable(self, tblname, columns=None, typeless=False): |
82 | | - """ |
83 | | - This function creates Table instance with current connection settings. |
84 | | - """ |
85 | | - return Replication.Table(parent=self, name=tblname, columns=columns, typeless=typeless) |
86 | | - |
87 | | - def dropTable(self, tblname): |
88 | | - """ |
89 | | - This function drops table with given name using current connection. |
90 | | - """ |
91 | | - self.cursor.execute('DROP TABLE IF EXISTS %s' % tblname) |
92 | | - |
93 | | - def __del__(self): |
94 | | - self.cursor.close() |
95 | | - self.connection.close() |
96 | | - |
97 | | - # sqlite data types |
98 | | - NULL = DataType('NULL') |
99 | | - INTEGER = DataType('INTEGER') |
100 | | - REAL = DataType('REAL') |
101 | | - TEXT = DataType('TEXT') |
102 | | - BLOB = DataType('BLOB') |
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +""" |
| 4 | +$Id$ |
| 5 | +
|
| 6 | +Copyright (c) 2006-2010 sqlmap developers (http://sqlmap.sourceforge.net/) |
| 7 | +See the file 'doc/COPYING' for copying permission |
| 8 | +""" |
| 9 | + |
| 10 | +from lib.core.exception import sqlmapMissingDependence |
| 11 | +from lib.core.exception import sqlmapValueException |
| 12 | + |
| 13 | +class Replication: |
| 14 | + """ |
| 15 | + This class holds all methods/classes used for database |
| 16 | + replication purposes. |
| 17 | + """ |
| 18 | + |
| 19 | + def __init__(self, dbpath): |
| 20 | + try: |
| 21 | + import sqlite3 |
| 22 | + except ImportError, _: |
| 23 | + errMsg = "missing module 'sqlite3' needed by --replicate switch" |
| 24 | + raise sqlmapMissingDependence, errMsg |
| 25 | + |
| 26 | + self.dbpath = dbpath |
| 27 | + self.connection = sqlite3.connect(dbpath) |
| 28 | + self.connection.isolation_level = None |
| 29 | + self.cursor = self.connection.cursor() |
| 30 | + |
| 31 | + class DataType: |
| 32 | + """ |
| 33 | + Using this class we define auxiliary objects |
| 34 | + used for representing sqlite data types. |
| 35 | + """ |
| 36 | + |
| 37 | + def __init__(self, name): |
| 38 | + self.name = name |
| 39 | + |
| 40 | + def __str__(self): |
| 41 | + return self.name |
| 42 | + |
| 43 | + def __repr__(self): |
| 44 | + return "<DataType: %s>" % self |
| 45 | + |
| 46 | + class Table: |
| 47 | + """ |
| 48 | + This class defines methods used to manipulate table objects. |
| 49 | + """ |
| 50 | + |
| 51 | + def __init__(self, parent, name, columns=None, create=True, typeless=False): |
| 52 | + self.parent = parent |
| 53 | + self.name = name |
| 54 | + self.columns = columns |
| 55 | + if create: |
| 56 | + self.parent.cursor.execute('DROP TABLE IF EXISTS %s' % self.name) |
| 57 | + if not typeless: |
| 58 | + self.parent.cursor.execute('CREATE TABLE %s (%s)' % (self.name, ','.join('%s %s' % (colname, coltype) for colname, coltype in self.columns))) |
| 59 | + else: |
| 60 | + self.parent.cursor.execute('CREATE TABLE %s (%s)' % (self.name, ','.join(colname for colname in self.columns))) |
| 61 | + |
| 62 | + def insert(self, values): |
| 63 | + """ |
| 64 | + This function is used for inserting row(s) into current table. |
| 65 | + """ |
| 66 | + if len(values) == len(self.columns): |
| 67 | + self.parent.cursor.execute('INSERT INTO %s VALUES (%s)' % (self.name, ','.join(['?']*len(values))), values) |
| 68 | + else: |
| 69 | + errMsg = "wrong number of columns used in replicating insert" |
| 70 | + raise sqlmapValueException, errMsg |
| 71 | + |
| 72 | + def select(self, condition=None): |
| 73 | + """ |
| 74 | + This function is used for selecting row(s) from current table. |
| 75 | + """ |
| 76 | + stmt = 'SELECT * FROM %s' % self.name |
| 77 | + if condition: |
| 78 | + stmt += 'WHERE %s' % condition |
| 79 | + return self.parent.cursor.execute(stmt) |
| 80 | + |
| 81 | + def createTable(self, tblname, columns=None, typeless=False): |
| 82 | + """ |
| 83 | + This function creates Table instance with current connection settings. |
| 84 | + """ |
| 85 | + return Replication.Table(parent=self, name=tblname, columns=columns, typeless=typeless) |
| 86 | + |
| 87 | + def dropTable(self, tblname): |
| 88 | + """ |
| 89 | + This function drops table with given name using current connection. |
| 90 | + """ |
| 91 | + self.cursor.execute('DROP TABLE IF EXISTS %s' % tblname) |
| 92 | + |
| 93 | + def __del__(self): |
| 94 | + self.cursor.close() |
| 95 | + self.connection.close() |
| 96 | + |
| 97 | + # sqlite data types |
| 98 | + NULL = DataType('NULL') |
| 99 | + INTEGER = DataType('INTEGER') |
| 100 | + REAL = DataType('REAL') |
| 101 | + TEXT = DataType('TEXT') |
| 102 | + BLOB = DataType('BLOB') |
0 commit comments