Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
Lab Advanced Software Development
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bui2.Huan@live.uwe.ac.uk
Lab Advanced Software Development
Commits
888c9b6f
Commit
888c9b6f
authored
2 weeks ago
by
Bui2.Huan@live.uwe.ac.uk
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
390dcd14
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Week 10/activity3.ipynb
+94
-0
94 additions, 0 deletions
Week 10/activity3.ipynb
with
94 additions
and
0 deletions
Week 10/activity3.ipynb
0 → 100644
+
94
−
0
View file @
888c9b6f
{
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Database created and connected successfully!\n"
]
}
],
"source": [
"import sqlite3\n",
"\n",
"try:\n",
" # Connect to (or create) myDB.db\n",
" conn = sqlite3.connect('myDB.db')\n",
"\n",
" print(\"Database created and connected successfully!\")\n",
"\n",
" # Commit changes and close\n",
" conn.commit()\n",
" conn.close()\n",
"\n",
"except sqlite3.Error as e:\n",
" print(f\"An error occurred: {e}\")\n"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(1, 'Bob', 'pka', 'Developer', 'bob@gmail.com')\n",
"(2, 'Bob', 'pka', 'Developer', 'bob@gmail.com')\n"
]
}
],
"source": [
"import sqlite3\n",
"\n",
"conn = sqlite3.connect('myDB.db')\n",
"cursor = conn.cursor()\n",
"\n",
"cursor.execute('''CREATE TABLE IF NOT EXISTS staff (\n",
" id INTEGER PRIMARY KEY AUTOINCREMENT,\n",
" name TEXT,\n",
" position TEXT,\n",
" office TEXT, \n",
" email TEXT\n",
")''')\n",
"\n",
"cursor.execute(\"INSERT INTO staff (name, position, office, email) VALUES (?, ?, ?,?)\",\n",
" ('Bob', 'Developer', 'pka','bob@gmail.com'))\n",
"\n",
"conn.commit()\n",
"\n",
"for row in cursor.execute('SELECT * FROM staff'):\n",
" print(row)\n",
"\n",
"conn.close()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
%% Cell type:code id: tags:
```
python
import
sqlite3
try
:
# Connect to (or create) myDB.db
conn
=
sqlite3
.
connect
(
'
myDB.db
'
)
print
(
"
Database created and connected successfully!
"
)
# Commit changes and close
conn
.
commit
()
conn
.
close
()
except
sqlite3
.
Error
as
e
:
print
(
f
"
An error occurred:
{
e
}
"
)
```
%% Output
Database created and connected successfully!
%% Cell type:code id: tags:
```
python
import
sqlite3
conn
=
sqlite3
.
connect
(
'
myDB.db
'
)
cursor
=
conn
.
cursor
()
cursor
.
execute
(
'''
CREATE TABLE IF NOT EXISTS staff (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT,
position TEXT,
office TEXT,
email TEXT
)
'''
)
cursor
.
execute
(
"
INSERT INTO staff (name, position, office, email) VALUES (?, ?, ?,?)
"
,
(
'
Bob
'
,
'
Developer
'
,
'
pka
'
,
'
bob@gmail.com
'
))
conn
.
commit
()
for
row
in
cursor
.
execute
(
'
SELECT * FROM staff
'
):
print
(
row
)
conn
.
close
()
```
%% Output
(1, 'Bob', 'pka', 'Developer', 'bob@gmail.com')
(2, 'Bob', 'pka', 'Developer', 'bob@gmail.com')
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment