💻
Code Snippet
  • Overview
  • General
    • Anaconda
  • GUI
    • PyQT
      • Qt Design
  • Pandas
    • Read Data
    • Replace
  • Articles
    • Python. PyQt
    • Offline Payment Wallet With Django
    • Documentation Encrypt File
    • Play With Pillow
  • Fontend
    • Snippet
    • Hugo
    • JavaScript
      • Form Validation
  • Finance
    • Library
      • yfinance
  • Notebook
    • Untitled
    • Snippet
  • Python
    • Download file
    • Date and Time
    • Snippet
    • Compile .exe
    • Overview
    • Google
      • Samples for Google Workspace
      • Drive
      • GoogleSheet
    • Virtual environment
    • Database
      • Pickle()
    • Datatypes
      • Excel
      • Dictionary
        • xmltodict()
    • File Handling
      • shutil()
      • Get the File Name
      • Get the Full Path
      • Check the File Size
      • Get File Creation Date
      • Find All File
        • Untitled
    • Dictionary
      • Convert Two Lists
  • Data Science
    • HTTP requests
  • Google Workspace
    • Overview
    • Apps Script
      • ์Note
      • Overview
      • Snippet
        • HTML Service
        • Fetch API
      • Quickstart
      • Google Sheets
        • Overview
          • Snippet
        • Fundamentals
          • Macros & Custom Functions
          • Spreadsheets, Sheets, and Ranges
          • Working with Data
          • Data Formatting
          • Chart and Present Data
        • Built-in Google Services
        • Fetch and format API data
        • Connected Sheets
  • Git
  • Mini Lab
    • Line
    • Python
  • Function
    • Python
      • Date&Time
  • Database
    • SQLite
      • Example
Powered by GitBook
On this page

Was this helpful?

  1. Database
  2. SQLite

Example

SQL Tutorials

import sqlite3

def demo_select():
    try:
        with sqlite3.connect("db.sqlite") as con:
            con.row_factory = sqlite3.Row
            # sql_cmd = "select * from person"
            sql_cmd = """
            select gender, height, weight, 
                  weight / ((height / 100) * (height / 100)) as bmi
                from person
                where gender = 'F' and bmi < 25
            """
            for row in con.execute(sql_cmd):
                # print(row)
                # print(row[1], row[2])
                print(row["gender"], row["height"], row["bmi"])
    except Exception as e:
        print('Error -> {}'.format(e))

def demo_select2():
    with sqlite3.connect("db.sqlite") as con:
        con.row_factory = sqlite3.Row
        sql_cmd = "select * from person2"
        for row in con.execute(sql_cmd):
            # print(row)
            # print(row[1], row[2])
            print(row["gender"], row["height"])

if __name__ == '__main__':
    demo_select()
PreviousSQLite

Last updated 3 years ago

Was this helpful?