Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
Oceano2python
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
Container 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
US191
Oceano2python
Commits
df2f7553
Commit
df2f7553
authored
2 years ago
by
Jacques Grelet
Browse files
Options
Downloads
Patches
Plain Diff
add sqlite test based on notanorm module
parent
67524189
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
db.py
+86
-0
86 additions, 0 deletions
db.py
with
86 additions
and
0 deletions
db.py
0 → 100644
+
86
−
0
View file @
df2f7553
from
notanorm
import
SqliteDb
# https://github.com/AtakamaLLC/notanorm
# https://www.sqlitetutorial.net
# https://www.sqlitetutorial.net/sqlite-create-table/
# https://www.sqlite.org
# https://stackoverflow.com/questions/1309989/parameter-substitution-for-a-sqlite-in-clause
# https://www.sqlitetutorial.net/sqlite-autoincrement/
def
main
():
#fname = 'tests/profiles.db'
fname
=
"
:memory:
"
db
=
SqliteDb
(
fname
)
table_station
=
"""
CREATE TABLE station (
id INTEGER PRIMARY KEY,
date_time TEXT NOT NULL UNIQUE,
julian_day REAL NOT NULL UNIQUE,
latitude REAL NOT NULL ,
longitude REAL NOT NULL,
max_depth REAL,
bottom_depth REAL
);
"""
# the id is actually the rowid AUTOINCREMENT column.
table_profile
=
"""
CREATE TABLE profile (
id INTEGER PRIMARY KEY,
station_id INTEGER,
PRES REAL NOT NULL,
FOREIGN KEY (station_id)
REFERENCES station (id)
);
"""
print
(
'
Create table station
'
)
#db.query("DROP DATABASE IF EXISTS '{}'".format(fname))
db
.
query
(
table_station
)
print
(
'
Create table profile
'
)
db
.
query
(
table_profile
)
for
pm
in
(
"
TEMP
"
,
"
PSAL
"
):
print
(
'
\t
Update table profile with new column {}
'
.
format
(
pm
))
addColumn
=
"
ALTER TABLE profile ADD COLUMN {} REAL NOT NULL
"
.
format
(
pm
)
db
.
query
(
addColumn
)
print
(
'
Insert data in table station
'
)
db
.
insert
(
"
station
"
,
id
=
1
,
date_time
=
"
2022-04-06 12:00:00.000
"
,
julian_day
=
10.5
,
latitude
=
-
10.2
,
longitude
=
23.6
)
db
.
insert
(
"
station
"
,
id
=
2
,
date_time
=
"
2022-04-07 17:00:00.000
"
,
julian_day
=
11.5
,
latitude
=
-
10.2
,
longitude
=
23.6
,
max_depth
=
2001
,
bottom_depth
=
5032
)
column
=
"
id
"
result_set
=
db
.
select
(
'
station
'
,
{
column
:
1
})
for
result
in
result_set
:
print
(
result
)
result_set
=
db
.
select
(
'
station
'
,
{
column
:
2
})
for
result
in
result_set
:
print
(
result
)
print
(
'
Insert data in profile table
'
)
db
.
insert
(
"
profile
"
,
station_id
=
1
,
PRES
=
1
,
TEMP
=
20
,
PSAL
=
35
)
db
.
insert
(
"
profile
"
,
station_id
=
1
,
PRES
=
2
,
TEMP
=
21
,
PSAL
=
35
)
db
.
insert
(
"
profile
"
,
station_id
=
1
,
PRES
=
3
,
TEMP
=
22
,
PSAL
=
35
)
db
.
insert
(
"
profile
"
,
station_id
=
1
,
PRES
=
3
,
TEMP
=
22
,
PSAL
=
35
)
db
.
insert
(
"
profile
"
,
station_id
=
2
,
PRES
=
4
,
TEMP
=
20
,
PSAL
=
35
)
db
.
insert
(
"
profile
"
,
station_id
=
2
,
PRES
=
5
,
TEMP
=
21
,
PSAL
=
35
)
db
.
insert
(
"
profile
"
,
station_id
=
2
,
PRES
=
6
,
TEMP
=
22
,
PSAL
=
35
)
db
.
insert
(
"
profile
"
,
station_id
=
2
,
PRES
=
7
,
TEMP
=
21.5
,
PSAL
=
35
)
db
.
insert
(
"
profile
"
,
station_id
=
2
,
PRES
=
7
,
TEMP
=
21.5
,
PSAL
=
35
)
print
(
'
Display join from station an profile tables
'
)
column
=
"
id
"
# select profile join station
result_set
=
db
.
select
(
'
profile
'
,
{
"
station_id
"
:
2
},
'
station
'
)
for
result
in
result_set
:
print
(
result
)
print
(
'
get sizes:
'
)
st
=
db
.
query
(
'
SELECT COUNT(id) FROM station
'
)
max_press
=
db
.
query
(
'
SELECT MAX(PRES) FROM profile
'
)
print
(
st
,
max_press
)
if
__name__
==
"
__main__
"
:
main
()
\ No newline at end of file
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