程序中有一个数据库锁,我该如何解决?
插入产品位工作正常,只是类别位告诉我数据库已锁定且不起作用:
<html>
<style>
</style>
<body>
<?php
$v_company= array(
'ABC'=>
array('Kuching'=>array('Michael', 'Jenny'),
'Sibu'=>array('Sally', 'Muhammad', 'Mutu')
),
'XYZ'=>array('Kuching'=>array('Lucy', 'Abdullah'),
'Sibu'=>array('John', 'Alicia')
)
);
?>
<table>
<tr><th>Company's Name</th>
<th>Branch</th>
<th>Staff's Name</th>
</tr>
<?php
$company = '';
$branch = '';
$staff = '';
foreach($v_company as $v_company_name=>$v_company_info){
foreach($v_company_info as $v_branch=>$v_staffs){
foreach($v_staffs as $v_staff){
echo "<tr>";
echo "<td>";
if($company == '' || $company != $v_company_name){
$company = $v_company_name;
echo "$v_company_name <br>";
}
echo "</td>";
echo "<td>";
if($branch != $v_branch){
$branch = $v_branch;
echo "$v_branch <br>";
}
echo "</td>";
echo "<td>";
echo "$v_staff <br/>";
echo "</td>";
echo "</tr>";
}
}
}
?>
</table>
</body>
</html>
我得到的问题是:
import sqlite3
def insert_product(product):
with sqlite3.connect("main.db") as db:
cursor = db.cursor()
sql = "insert into Products (CatID,Name,Qty,Price) values (?, ?, ?, ?)"
cursor.execute(sql, product)
db.commit()
print("The product {0} has been inserted successfully" .format(Name))
cursor = db.execute("SELECT ProductID, CatId, Name, Qty, Price from Products")
for row in cursor:
print ("ID = ", row[0])
print ("CatID = ", row[1])
print ("NAME = ", row[2])
print ("Qty = ", row[3])
print ("Price = ", row[4], "\n")
def insert_category(category):
with sqlite3.connect("main.db") as db:
cursor = db.cursor()
sql = "insert into categories (Name) values (?)"
cursor.execute(sql, category)
db.commit()
print("The category {0} has been inserted successfully" .format(Name))
cursor = db.execute("SELECT CatID,Name from categories")
for row in cursor:
print ("CatID = ", row[0])
print ("Name = ", row[1], "\n")
if __name__ == "__main__":
response = input("Do you want to insert a category or a product (c/p) ?")
if response == "p":
ID= input("enter the CatID of the product:>> ")
Name = input("Enter the name of the Product you want to insert: >>")
Qty = input("Enter the quantity of the stock available: >>")
Price = input("Enter the price of the product: >>")
product = (ID,Name,Qty,Price)
insert_product(product)
print ("Product inserted successfully")
else:
Name = input("Enter the name of the Category you want to insert: >>")
category = (Name,)
insert_category(category)
db.commit()
print ("The new category {0} has been inserted successfully" .format(Name))