Understanding Database 11 - Database Programming Techniques
2023. 1. 16. 09:45ㆍData science/Database
반응형
Database Application system
# 3-Tier Architecture
- Client: GUI, Web interface, display of info [i.e. HTML, CSS, JS]
- Application server or Web server: Application programs, web pages - stores biz rules, implement logic [i.e. divided by NodeJS, Python, Java, PHP, C; host language + SQL, NoSQL; Data sub-language]
- Database server: Database Management System - hosts DBMS (accept and process queries and commands) [i.e. MySQL, MongoDB]
- Interactive interface: interface where SQL/NoSQL commands can be typed directly into a monitor for execution
- Execute file of command: file created through an interactive interface (import tool; PHPMyAdmin, typing @<filename> in oracle)
- Application program: used as canned transactions by end users to query DB or execute transactions on DB (making airline reservations)
#The sequence of Interaction in the DB program
- Client program opens or establishes a connection to DB server
- Client program submits queries or updates to the DB
- No access needed -> Client program closes or terminates the connection to DB
#Approach to DB programming: Application Program
- Using a library of DB functions or classes to connect DB, prepare and execute a query, execute an update, loop over the query result
- Embedding DB command in a general-purpose programming language, where a precompiled scans the source code, identify and extract database statement for processing by DBMS
- Designing a brand-new language from scratch is compatible with the DB model and query language - usually referred to as DB programming language.
## Using a library of DB functions
- Include/import the library of functions- API -> 1
- create a connection to DB
- prepare SQL statements and parameters
- Execute SQL
- process query results
- retrieve values from the processed query result
- output result
*** Cursor: control structure that enables iteration over records in DB (loop over query results, one record at a time)
- Initialize a cursor pointing to DB -> 7(python example)
- Execute SQL/NoSQL statements to DB using cursor -> 8(python example)
- fetch data into local variables from cursor (One tuple at a time) -> 9(python example)
- iterates over -> 10, 11(python example)
- close the cursor when done fetching all tuples -> 12(python example)
## Embedding DB command in a general-purpose programming language: Stored Procedure
stored and executed by DBMS at the DB server (The other two are in application server)
- when it needed several application , if reduction in data transfer required, enhance the process of generating views
Databse Programming Techinque issues
- Impedance mismatch occurs as a result of incompatibilities between a host programming language model and the database model – programming language data type differs from attributes data type.
- Therefore, a different binding is needed for each programming language and DBMS because different programming languages have different data types
- A binding is required to map each query result’s data structure (table), to the appropriate data structure in the programming language.
- A mechanism is required to loop over the query result (one tuple at a time) to extract individual values from the tuples.
반응형
'Data science > Database' 카테고리의 다른 글
Understanding database - NoSQL 한 장으로 총정리 (1) | 2023.01.23 |
---|---|
Understanding Database - SQL 기초 총정리 (2) | 2023.01.23 |
Understanding Database 10 - Data modelling with MongoDB (0) | 2023.01.16 |
Understanding Database 9 - Distributed Database Systems(DDB) (0) | 2023.01.16 |
Understanding Database 8 - NoSQL + Python Basic (0) | 2023.01.16 |