示例#1
0
def get_db():
    if 'db' not in g:
        g.db = sqllite3.connect(current_app.config('DATABASE'),
                                detect_types=sqllite3.PARSE_DECLTYPES)
        g.db.row_factory = sqllite3.Row

    return g.db
# !/usr/bin/env python3
import cgi
import sqllite3

f = cgi.FieldStorage().getvalue("username")
q = cgi.FieldStorage().getvalue("password")

db = sqllite3.connect("account.db")
coursor = db.cursor()

coursor.execute("""CREATE TABLE """)

print("Content-type: text/html")
print()
print(q)
示例#3
0
def load_real_cakes():
    conn = sqllite3.connect(sqllite_file)
    c = conn.cursor()
示例#4
0
#!/usr/bin/python
# -*- coding: utf-8 -*-

import sqllite3 as sql
import sys

con = sql.connect('test.db')

with con:
    
    cur = con.cursor()    
    cur.execute("CREATE TABLE Cars(Id INT, Name TEXT, Price INT)")
    cur.execute("INSERT INTO Cars VALUES(1,'Audi',52642)")
    cur.execute("INSERT INTO Cars VALUES(2,'Mercedes',57127)")
    cur.execute("INSERT INTO Cars VALUES(3,'Skoda',9000)")
    cur.execute("INSERT INTO Cars VALUES(4,'Volvo',29000)")
    cur.execute("INSERT INTO Cars VALUES(5,'Bentley',350000)")
    cur.execute("INSERT INTO Cars VALUES(6,'Citroen',21000)")
    cur.execute("INSERT INTO Cars VALUES(7,'Hummer',41400)")
    cur.execute("INSERT INTO Cars VALUES(8,'Volkswagen',21600)")

cur.execute("INSERT INTO sct VALUES(1,'Audi',52642)")
cur.execute("INSERT INTO sct VALUES(2, 'mark', '2012-01-01')")

con.commit()
示例#5
0
 def connect():
     self.conn = sqllite3.connect(self.dbName)
示例#6
0
#!/usr/bin/local/python3

__author__ = 'Swapnil Khedekar'

import sqllite3

conn = sqllite3.connect("company.db")
conn.execute("select * from emp;")
示例#7
0
文件: sqla.py 项目: mani-python/sql
#!/usr/bin/env python
import sqllite3

conn = sqllite3.connect("new.db")
cursor = conn.cursor()
cursor.execute("""CREATE TABLE population (city TEXT,state TEXT, population INT)""")
conn.close()
示例#8
0
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import sqllite3
conn = sqllite3.connect('test.db')
cursor = conn.cursor()

""" Describe file """

import sqllite3

conn = sqllite3.connect('Name_of_database')

#Put your variables here.

def make_db()
  """ Describe this function here """
  curs = conn.cursor()
  #execute your queries to create database and insert
  curs.close()
  conn.commit()

def run_queries()
  """ Describe this function here """
  curs.cursor()
  print(curs.execute('SELECT * from table;').fetchall())

if __name__ == "__main__"
  make_db()
  run_queries()  
import sqllite3

con = sqllite3.connect('tienda.db')

c = con.cursor()

c.execute('''
    CREATE TABLE Cliente
    (idCliente PRIMARY KEY ASC, nombreCliente VARCHAR(200) NOT NULL)
''')

con.comit()
con.close()
#creating database with sqllite3
#connect with userinterface


import sqllite3 
with sqllite3.connect (sql.db) as db:
示例#12
0
import sqllite3 as SQ
db1 = SQ.connect('test.db')
db2 = SQ.connect(':memory:')
c = db1.cursor()
c.execute (create table a (id int, name varchar(20)))
c.close()
for index, name in enumerate (('Bill', 'John', 'Mary', 'Rob', 'Tom'))
    c = db1.cursor()
    c.execute('insert into a (id, name) values (?,?)', (index, name))
    c.close()
    db.commit()
c = db1.cursor()
c1 = c.execute('select * from a')
c1.fetchone()
c1.fetchmany(2)
c1.fetchall()
c.close()
c1.close()

c = db1.cursor()
c1 = c.execute('select * from a')
for row in c1:
    print (row)
c.close()
c1.close()

c = db1.cursor()
name = "John"
print (c.execute('select * from a where name =? (?,?)', (name,)))
db1.close()
db2.close()
示例#13
0
import sqllite3

conn = sqllite3.connect('escola.db')

cursor = conn.cursor()

cursor.execute("""
    CREATE TABLE tb_aluno(
    id_aluno INTEGER NOT NULL PRIMARY AUTOINCREMENT,
    nome VARCHAR(45),
    matricula VARCHAR(12) NOT NULL,
    cpf VARCHAR(11) NOT NULL,
    nascimento DATE NOT NULL
    );
""")
print("tabela aluno criada com sucesso!")

cursor.execute("""
    CREATE TABLE tb_curso(
        id_curso INTEGER NOT NULL PRIMATY KEY INCREMENT,
        nome VARCHAR(45) NOT NULL,
        turno VARCHAR(1) NOT NULL
    );
""")
print("tabela curso criada com sucesso!")

cursor.execute("""
    CREATE TABLE tb_turma(
        id_turma INTEGER NOT NULL PRIMARY AUTOINCREMENT,
        FK id_curso VARCHAR(45) NOT NULL
    );
import sqllite3

class MyClass:
    
    def __init__(self, path)
        self.__conn = sqllite3.connect(path)
        
    def store_data(self, data):
        cursor = self.__conn.cursor()
        cursor.execute("INSERT INTO contractors VALUES (?, ?)", (3, "Helena"))
        
        

class MyBetterClass:
    
    def __init__(self, conn)
        self.__conn = conn
        
    def store_data(self, data):
        cursor = self.__conn.cursor()
        cursor.execute("INSERT INTO contractors VALUES (?, ?)", (3, "Helena"))
示例#15
0
import time
import threading
import sqllite3 as sql

ping_data = "PING\r\n"

Naveen_ip = "192.168.10.100"
Ramesh_ip = "192.168.10.163"

PORT = 456

USERNAME = raw_input("Enter your user name: ")

nameserver = {}

db = sql.connect("namelsit.db")
db_cursor = db.cursor()

try:
	data_in_db = db_cursor.execute("SELECT * FROM namelist")
	
except error:
	db_cursor.execute("CREATE TABLE namelist('name','address')")
	data_in_db = db_cursor.execute("SELECT * FROM namelist")

name_dict = db_to_dict(data_in_db)

if USERNAME in name_dict:
	if (name_dict[USERNAME] is str(socket.gethostbyname(socket.gethostname()))):
		continue
	else:
import sqllite3
try:
    con = sqllite3.connect("test_db")  #   connection establishment
    cur = con.cursor()  #   creation of cursor
    cur.execute("DROP TABLE IF EXISTS Employee")
    cur.execute('CREATE TABLE EMPLOYEE (id INT, name VARCHAR, city VARCHAR)')
    cur.execute("INSERT INTO EMPLOYEE VALUES(1,'pavan','chennai')")
    con.commit()
    cur.execute("SELECT * FROM EMPLOYEE")
    data = cur.fetchall()
    for row in data:
        print(row)
except sqllite3.Error as e:
    if con:
        con.rollback()
        print("There was a problem occured")
finally:
    if con:
        con.close()
示例#17
0
def open_connection():
    connection = getattr(g,'_connection',None)
    if connection == None:
        connection=g._connection=sqllite3.connect(PATH)
        connection.row_factory=sqllite3.Row
        return.connection