Example #1
1
def main():
    db = Database(name="pythontest")

    ##  q = raw_input("Do You want to create New Database(Yes/No)?")
    ##  if q.lower() == 'yes':
    ##    name = raw_input("Please enter the Database name:")
    ##    db = Database(name)

    # Create Table Customers
    table = "customers"
    sql = """
      CREATE TABLE IF NOT EXISTS {} (
        id int NOT NULL AUTO_INCREMENT,
        first_name  VARCHAR(50),
        last_name   VARCHAR(50),
        phone       VARCHAR(15),
        email       VARCHAR(100),
        address     VARCHAR(150),
        country     VARCHAR(30),
        PRIMARY KEY(id)
      )
  """.format(
        table
    )

    msg = "Table {} Created successfully.".format(table) if db.create(sql) else "Table {} already exists.".format(table)
    print msg

    # Create Table Products
    table = "products"
    sql = """
      CREATE TABLE IF NOT EXISTS {}(
        id int NOT NULL AUTO_INCREMENT,
        name        VARCHAR(50),
        price       FLOAT(11,2),
        description TEXT,
        PRIMARY KEY(id) )
  """.format(
        table
    )

    msg = "Table {} Created successfully.".format(table) if db.create(sql) else "Table {} already exists.".format(table)
    print msg

    # Create Table Orders
    table = "orders"
    sql = """
      CREATE TABLE IF NOT EXISTS {} (
        id int NOT NULL AUTO_INCREMENT,
        customer_id INT(11),
        product_id INT(11),
        quantity INT(11),
        price FLOAT(11,2),
        PRIMARY KEY(customer_id, product_id),
        KEY(id)
      )
  """.format(
        table
    )

    msg = "Table {} Created successfully.".format(table) if db.create(sql) else "Table {} already exists.".format(table)
    print msg

    # INSERTING DUMMY DATA FOR TABLES customers, products, orders
    sql = """
      INSERT INTO customers(first_name, last_name, phone, email, address, country)
      VALUES
        ('Goren', 'AngelKovski', '38971371213', 'info@newmediacorp.com', 'Bitola, Fyro', 'Macedonia'),
        ('Nawazish', 'Qadir', '923314133340', 'nawazish@gmail.com', 'Dera Ghazi Khan', 'Pakistan');
  """
    db.insert(sql)

    sql = """
      INSERT INTO products(name, price, description)
      VALUES
        ('Facial Skin Care', 5.0, 'Awesome product to use for facial.'),
        ('Synology Storage', 25.0, 'Product with storing network attached data.');
  """
    db.insert(sql)

    sql = """
      INSERT INTO orders(customer_id, product_id, quantity, price)
      VALUES
        (1, 1, 25, 35.55),
        (1, 2, 12, 45);
  """
    db.insert(sql)

    #   Delete database
    sql = """
      DROP DATABASE pythontest
  """
    db.get_dump()
    # db.delete(sql)

    db = Database(name="pythontest")
    db.restore()
Example #2
1
 def POST(self):
     i = web.input()
     n = db.insert("student", name=i.name)
     raise web.seeother("/")