Chapterبەش 9 · Lectureوانە 9.9

SQLite Basicsبنەماکانی SQLite

What SQLite is (a serverless database in one file), why it is used, where it came from, the SQL command families DDL, DML, DQL and DCL (and TCL), case sensitivity with LIKE and GLOB, phpLiteAdmin, and how PHP uses SQLite through PDO. Every example was run on SQLite.

SQLite چییە (بنکەدراوەیەکی بێ‌ڕاژەکار لە یەک فایلدا)، بۆچی بەکاردێت، لە کوێوە هاتووە، خێزانەکانی فەرمانی SQL واتە DDL و DML و DQL و DCL (و TCL)، هەستیاری بە پیتی گەورە و بچووک لەگەڵ LIKE و GLOB، phpLiteAdmin و PHP چۆن لە ڕێگەی PDOـەوە SQLite بەکاردەهێنێت. هەموو نموونەیەک لەسەر SQLite جێبەجێ کراوە.

20 min read20 خولەک خوێندنەوە · 16 stepsهەنگاو

What you will learnچی فێر دەبیت

  • Explain what SQLite is and how a serverless, single-file database differs from a client–server database like MySQL.
  • Give the reasons for using SQLite and the main facts of its history.
  • Sort SQL commands into DDL, DML, DQL, DCL and TCL, and know that SQLite has no DCL.
  • Predict the results of =, LIKE and GLOB with upper- and lower-case text.
  • Create, fill and read an SQLite database from PHP with PDO.
  • ڕوونی بکەیتەوە SQLite چییە و بنکەدراوەیەکی بێ‌ڕاژەکار و یەک‌فایلی چ جیاوازییەکی لەگەڵ بنکەدراوەیەکی ڕاژەخواز و ڕاژەکاری وەک MySQL هەیە.
  • هۆکارەکانی بەکارهێنانی SQLite و ڕاستییە سەرەکییەکانی مێژووەکەی بڵێیت.
  • فەرمانەکانی SQL بە سەر DDL و DML و DQL و DCL و TCLـدا دابەش بکەیت و بزانیت SQLite هیچ DCLـێکی نییە.
  • ئەنجامی = و LIKE و GLOB لەگەڵ دەقی پیتی گەورە و بچووک پێشبینی بکەیت.
  • بە PDO لە PHPـەوە بنکەدراوەیەکی SQLite دروست بکەیت، پڕی بکەیتەوە و بیخوێنیتەوە.

SQLite: a whole database in one fileSQLite: هەموو بنکەدراوەیەک لە یەک فایلدا

The SQLite logo: the word SQLite in green-grey letters with a feather.لۆگۆی SQLite: وشەی SQLite بە پیتی سەوزی بۆز لەگەڵ پەڕێک.
The SQLite logo.لۆگۆی SQLite.SQLite project (SVG by Raphael Javaux), via Wikimedia Commons · Public domain

Up to now our database has been MySQL (or MariaDB), which XAMPP runs as a separate server program. This lecture introduces a different kind of database: , which keeps a whole database, with every table and every row, inside one ordinary file. You will learn what it is and why people use it, where it came from, the families of SQL commands (DDL, DML, DQL and DCL), one rule about upper- and lower-case letters that surprises many people, the phpLiteAdmin tool, and how PHP talks to SQLite.

تا ئێستا MySQL (یان MariaDB) بووە، کە XAMPP وەک بەرنامەیەکی جیا کاری پێدەکات. ئەم وانەیە جۆرێکی تری بنکەدراوە دەناسێنێت: ، کە هەموو بنکەدراوەیەک، لەگەڵ هەموو خشتە و هەموو ڕیزێکی، لەناو یەک فایلی ئاساییدا هەڵدەگرێت. فێر دەبیت چییە و بۆچی خەڵک بەکاری دەهێنن، لە کوێوە هاتووە، خێزانەکانی فەرمانی ⁦SQL (DDL⁩، DML، DQL و DCL)، یاسایەک دەربارەی پیتی گەورە و بچووک کە زۆر کەس سەری لێ سوڕ دەمێنێت، ئامرازی phpLiteAdmin و PHP چۆن قسە لەگەڵ SQLite دەکات.

What SQLite isSQLite چییە

Definitionپێناسە

A small database engine that keeps a whole in one ordinary file. It needs no separate server () and no setup, and PHP can use it through .

بزوێنەرێکی بچووکی بنکەدراوەیە کە هەموو بنکەدراوەیەک لە یەک فایلی ئاساییدا هەڵدەگرێت. پێویستی بە ڕاژەکاری جیا نییە () و هیچ ڕێکخستنێکی ناوێت و PHP دەتوانێت لە ڕێگەی بەکاری بهێنێت.

  • A database engine. SQLite is software that lets you work with a : data kept in tables of rows and columns. A database engine is the software that stores the data and answers your questions about it.
  • One file. The whole database is stored in a single file. This is what makes SQLite different from other database engines: copy that one file and you have copied the whole database, with every table and every row inside it.
  • Zero configuration. There is no server to install, no user to create and no port to open. You point your code at a file and start working.
  • Not a separate process. SQLite is not something you start and stop. It is a that is linked into your program, statically or dynamically, and becomes part of the application itself. In PHP it is built into the pdo_sqlite and sqlite3 extensions.
  • Direct access. SQLite reads and writes its storage file directly. There is no middleman between your code and the file.
  • بزوێنەرێکی . SQLite نەرمەکاڵایەکە کە ڕێگەت پێدەدات کار لەگەڵ بکەیت: دراوە لە خشتەی ڕیز و ستووندا. بزوێنەری بنکەدراوە ئەو نەرمەکاڵایەیە کە دراوەکان هەڵدەگرێت و وەڵامی پرسیارەکانت دەربارەیان دەداتەوە.
  • یەک فایل. هەموو بنکەدراوەکە لە یەک فایلدا هەڵدەگیرێت. ئەمە ئەوەیە کە SQLite لە بزوێنەرەکانی تری بنکەدراوە جیا دەکاتەوە: ئەو یەک فایلە کۆپی بکە و هەموو بنکەدراوەکەت کۆپی کردووە، لەگەڵ هەموو خشتە و هەموو ڕیزێکی ناوی.
  • بێ ڕێکخستن. هیچ ڕاژەکارێک نییە بۆ دامەزراندن، هیچ بەکارهێنەرێک نییە بۆ دروستکردن و هیچ نییە بۆ کردنەوە. کۆدەکەت ئاڕاستەی فایلێک دەکەیت و دەست بە کار دەکەیت.
  • پرۆسەیەکی جیا نییە. SQLite شتێک نییە کە دەستی پێبکەیت و ڕایبگریت. کە دەبەسترێتەوە بە بەرنامەکەتەوە، بە شێوەی ستاتیک یان داینامیک و دەبێت بە بەشێک لە خودی بەرنامەکە. لە PHPـدا لەناو پاشکۆکانی pdo_sqlite و sqlite3دا دروستکراوە.
  • دەستڕاگەیشتنی ڕاستەوخۆ. SQLite ڕاستەوخۆ فایلی هەڵگرتنەکەی دەخوێنێتەوە و تێیدا دەنووسێت. هیچ ناوەندگیرێک لە نێوان کۆدەکەت و فایلەکەدا نییە.
Definitionپێناسە

Working without a separate database server program. is serverless: your PHP code reads and writes the database file directly. (In cloud computing, 'serverless' has a different meaning.)

کارکردن بەبێ بەرنامەیەکی جیای ڕاژەکاری بنکەدراوە. بێ‌ڕاژەکارە: کۆدی PHPـەکەت ڕاستەوخۆ فایلی بنکەدراوەکە دەخوێنێتەوە و تێیدا دەنووسێت. (لە کۆمپیوتەریی هەوریدا، serverless واتایەکی تری هەیە.)

"Serverless" here means that SQLite does not need a separate server process or system to work. In cloud computing the same word means something else (renting computing power without managing servers), so do not mix the two.

«» لێرەدا واتە SQLite پێویستی بە پرۆسە یان سیستەمێکی ڕاژەکاری جیا نییە بۆ کارکردن. لە کۆمپیوتەریی هەوریدا هەمان وشە واتایەکی ترە (بەکرێگرتنی توانای ژمێریاری بەبێ بەڕێوەبردنی ڕاژەکار)، بۆیە ئەم دووانە تێکەڵ مەکە.

Comparison diagram. Left, client–server: your PHP script and phpMyAdmin connect over the network (host, port 3306, user, password) to a separate MySQL server program, which alone opens the data files. Right, SQLite: the SQLite library is linked inside PHP, and both your script and phpLiteAdmin read and write the file school.db directly. A table compares setup (server, users and permissions versus nothing but a file path), the connection code, and what each is good for.وێنەی بەراوردکردن. لای چەپ، ڕاژەخواز و ڕاژەکار: دەسنووسی PHPـەکەت و phpMyAdmin بە ڕایەڵەدا (host، port 3306، user، password) پەیوەندی دەکەن بە بەرنامەیەکی جیای ڕاژەکاری MySQLـەوە، کە تەنها خۆی فایلەکانی دراوە دەکاتەوە. لای ڕاست، SQLite: کتێبخانەی SQLite لەناو PHPـدا بەستراوە و هەم دەسنووسەکەت و هەم phpLiteAdmin ڕاستەوخۆ فایلی school.db دەخوێننەوە و تێیدا دەنووسن. خشتەیەک ئامادەکردن (ڕاژەکار، بەکارهێنەر و مۆڵەت بەرامبەر بە تەنها ڕێڕەوی فایلێک)، کۆدی پەیوەندی و ئەوەی هەر یەکێکیان بۆی گونجاوە بەراورد دەکات.
SQLite compared with a client–server database such as MySQL.بەراوردی SQLite لەگەڵ بنکەدراوەیەکی ڕاژەخواز و ڕاژەکار وەک MySQL.CêIT
A tea house and a flaskچایخانە و فلاسک

A client–server database is like a tea house. You give your order to a waiter, the kitchen makes it, and the waiter brings it back. The tea house has staff, opening hours and many customers at once. SQLite is like a flask of tea in your own bag: no waiter and no opening hours, ready wherever you are, because the tea is already with you.

بنکەدراوەیەکی ڕاژەخواز و ڕاژەکار وەک چایخانەیەک وایە. داواکارییەکەت دەدەیتە گارسۆنێک، چێشتخانەکە ئامادەی دەکات و گارسۆنەکە بۆتی دەهێنێتەوە. چایخانەکە کارمەند و کاتی کردنەوە و زۆر میوانی پێکەوەی هەیە. SQLite وەک فلاسکێکی چای وایە لەناو جانتاکەی خۆتدا: نە گارسۆن و نە کاتی کردنەوە، لە هەر شوێنێک بیت ئامادەیە، چونکە چاکە پێشتر لەگەڵ خۆتە.

Where the analogy stops workingسنووری ئەم نموونەیە

A flask is for one person, but many programs can read an SQLite file at the same time. Only writing is limited: one writer at a time.

فلاسک بۆ یەک کەسە، بەڵام زۆر بەرنامە دەتوانن لە هەمان کاتدا فایلێکی SQLite بخوێننەوە. تەنها نووسین سنووردارە: لە یەک کاتدا یەک نووسەر.

Quick checkپشکنینی خێراWhat does "serverless" mean for SQLite? بۆ SQLite چ واتایەکی هەیە؟

Why SQLite?بۆچی SQLite؟

The reasons the course slides give for SQLite.ئەو هۆکارانەی سلایدەکانی کۆرسەکە بۆ SQLite دەیهێننەوە.
ReasonهۆکارWhat it meansواتاکەی
ServerlessSQLite does not require a separate server process or system to operate.SQLite پێویستی بە پرۆسە یان سیستەمێکی ڕاژەکاری جیا نییە بۆ کارکردن.
Zero-configurationبێ ڕێکخستنNo setup or administration is needed.هیچ ئامادەکردن یان بەڕێوەبردنێک پێویست نییە.
One cross-platform fileیەک فایلی A complete database is stored in a single disk file, and the same file opens on a phone, a laptop and a server, with no change at all.بنکەدراوەیەکی تەواو لە یەک فایلی دیسکدا هەڵدەگیرێت و هەمان فایل لەسەر مۆبایل، لاپتۆپ و ڕاژەکار دەکرێتەوە، بەبێ هیچ گۆڕانکارییەک.
Small and lightبچووک و سووکThe whole library is under about 1 MB with every feature turned on, and smaller without optional features. A single phone photo is usually larger.هەموو کتێبخانەکە بە هەموو تایبەتمەندییەکانەوە لە نزیکەی ١ مێگابایت کەمترە و بەبێ تایبەتمەندییە ئارەزوومەندانەکان بچووکترە. یەک وێنەی مۆبایل زۆرجار گەورەترە.
Self-containedخۆبەسەندIt has no external dependencies: it needs no other software to run.هیچ پشتبەستنێکی دەرەکی نییە: پێویستی بە هیچ نەرمەکاڵایەکی تر نییە بۆ کارکردن.
Follows the SQL standardپەیڕەوی ستانداردی SQL دەکاتIt supports most of the query language of SQL-92 (also called SQL2), a 1992 edition of the international SQL standard.زۆربەی زمانی پرسکردنی ⁦SQL-92⁩ (کە پێی دەوترێت ⁦SQL2⁩ـیش) پشتگیری دەکات، کە وەشانێکی ١٩٩٢ـی ستانداردی نێودەوڵەتیی SQLـە.

SQLite is available on UNIX, Linux, macOS (formerly Mac OS X), Android, iOS and Windows (Win32, and the older WinCE and WinRT).

SQLite لەسەر UNIX، Linux، macOS (پێشتر ⁦Mac OS X⁩)، Android، iOS و ⁦Windows (Win32⁩ و WinCE و WinRTـی کۆنتر) بەردەستە.

Quick checkپشکنینی خێراWhere does SQLite keep a whole database?SQLite هەموو بنکەدراوەیەک لە کوێ هەڵدەگرێت؟

Where SQLite came fromSQLite لە کوێوە هات

  • 2000: D. Richard Hipp designed SQLite so that no administration would be needed to run a program with a database. He was working for General Dynamics on a contract with the US Navy at the time, and version 1.0 came out in August 2000. The aim from the first day was "a database nobody has to look after".
  • 2004: SQLite version 3 was released. It is the version everyone uses today, and PHP's sqlite3 extension is named after it.
  • 2011: Hipp announced UnQL, a query language for document databases, and plans for a NoSQL interface to SQLite. That interface never became part of SQLite.
  • Today: SQLite is still free: its code is in the public domain, so anyone may use it for any purpose.
  • ٢٠٠٠: SQLite لەلایەن ⁦D. Richard Hipp⁩ـەوە دیزاین کرا بۆ ئەوەی هیچ بەڕێوەبردنێک پێویست نەبێت بۆ کارپێکردنی بەرنامەیەک کە بنکەدراوەی هەیە. Hipp لەو کاتەدا بۆ ⁦General Dynamics⁩ لەسەر گرێبەستێک لەگەڵ هێزی دەریایی ئەمریکا کاری دەکرد و وەشانی ⁦1.0⁩ لە ئابی ٢٠٠٠دا دەرچوو. ئامانج لە یەکەم ڕۆژەوە «بنکەدراوەیەک بوو کە کەس پێویست نەکات چاودێری بکات».
  • ٢٠٠٤: وەشانی 3ـی SQLite بڵاوکرایەوە. ئەو وەشانەیە کە ئەمڕۆ هەموو کەس بەکاری دەهێنێت و پاشکۆی sqlite3ـی PHP بەو ناوە ناونراوە.
  • ٢٠١١: Hipp زمانی UnQLی ڕاگەیاند، کە زمانێکی پرسکردنە بۆ ، هەروەها پلانی ڕووکارێکی NoSQLـی بۆ SQLite ڕاگەیاند. ئەو ڕووکارە هەرگیز نەبوو بە بەشێک لە SQLite.
  • ئەمڕۆ: SQLite هێشتا بەخۆڕاییە: کۆدەکەی ، بۆیە هەر کەسێک دەتوانێت بۆ هەر مەبەستێک بەکاری بهێنێت.

A document-oriented database is a different kind of database: it keeps whole documents (for example JSON objects) instead of rows in tables.

جۆرێکی جیاوازی بنکەدراوەیە: لە جیاتی ڕیز لەناو خشتەدا، بەڵگەنامەی تەواو هەڵدەگرێت (بۆ نموونە ئۆبجێکتی ).

Quick checkپشکنینی خێراWho designed SQLite, and when?کێ SQLiteی دیزاین کرد و کەی؟

The Code Inside Everything (That Gets Zero Credit)Coding with Lewis · Englishئینگلیزی · 346K viewsبینین · 14K likesلایک · Partبەشی 0:00–5:36 (ofلە 29:06)

The story of SQLite: why Richard Hipp made it during a US Navy project, and why a whole database fits in one file.

چیرۆکی : بۆچی ڕیچارد هیپ لە کاتی پڕۆژەیەکی هێزی دەریایی ئەمریکادا دروستی کرد و بۆچی تەواو لە یەک جێی دەبێتەوە.

Watch 0:00–5:36: the US Navy origin and the database in one file.

لە ⁦0:00⁩ تا ⁦5:36⁩ سەیر بکە: سەرەتاکەی لە هێزی دەریایی ئەمریکا و لە یەک .

SQLite commands: the familiesفەرمانەکانی SQLite: خێزانەکان

The commands you use with SQLite are SQL, the same language you used with MySQL (SQLite's own version of it). The slides group them by what they do:

ئەو فەرمانانەی لەگەڵ SQLite بەکاریان دەهێنیت SQLـن، هەمان ئەو زمانەی لەگەڵ MySQL بەکارت هێنا (وەشانی تایبەتی SQLite لێی). سلایدەکان بەپێی ئەو کارەی دەیکەن کۆیان دەکەنەوە:

The SQL command families from the course slides.خێزانەکانی فەرمانی SQL لە سلایدەکانی کۆرسەکەوە.
FamilyخێزانFull nameناوی تەواوCommandsفەرمانەکانWhat it doesچی دەکات
DDLData Definition LanguageCREATE, ALTER, DROPbuilds and changes the shape of the databaseشێوەی بنکەدراوەکە دروست دەکات و دەیگۆڕێت
DMLData Manipulation LanguageINSERT, UPDATE, DELETEchanges the rows that live inside itئەو ڕیزانە دەگۆڕێت کە لەناویدا دەژین
DQLData Query LanguageSELECTasks the database a questionپرسیارێک لە بنکەدراوەکە دەکات
DCLData Control LanguageGRANT, REVOKEgives and takes back permissions (not in SQLite)مۆڵەت دەدات و دەیسەنێتەوە (لە SQLite نییە)
Five boxes: DDL (CREATE, ALTER, DROP) builds and changes the shape, works in SQLite; DML (INSERT, UPDATE, DELETE) changes the rows, works in SQLite; DQL (SELECT) asks a question, works in SQLite; DCL (GRANT, REVOKE) gives or takes back permissions, not in SQLite but in MySQL; TCL (BEGIN, COMMIT, ROLLBACK, dashed as an extra family) groups changes so that all or none happen, works in SQLite.پێنج سندوق: DDL (CREATE، ALTER، DROP) شێوە دروست دەکات و دەیگۆڕێت، لە SQLite کار دەکات؛ DML (INSERT، UPDATE، DELETE) ڕیزەکان دەگۆڕێت، لە SQLite کار دەکات؛ DQL (SELECT) پرسیار دەکات، لە SQLite کار دەکات؛ DCL (GRANT، REVOKE) مۆڵەت دەدات یان دەیسەنێتەوە، لە SQLite نییە بەڵام لە MySQL هەیە؛ TCL (BEGIN، COMMIT، ROLLBACK، بە هێڵی پچڕاو وەک خێزانێکی زیادە) گۆڕانکارییەکان کۆدەکاتەوە بۆ ئەوەی یان هەموویان یان هیچیان ڕوو بدەن، لە SQLite کار دەکات.
SQL command families, and which ones SQLite supports.خێزانەکانی فەرمانی SQL و کامیان SQLite پشتگیری دەکات.CêIT
Quick checkپشکنینی خێراWhich three commands belong to DDL?کام سێ فەرمان سەر بە DDLـن؟

SQLite commands: the familiesفەرمانەکانی SQLite: خێزانەکان

DDL: building the shapeDDL: دروستکردنی شێوە

Definitionپێناسە

The SQL commands that define the structure of a database: CREATE, ALTER and DROP. They change tables, not the data inside them.

ئەو فەرمانانەی SQL کە پێکهاتەی پێناسە دەکەن: CREATE، ALTER و DROP. خشتەکان دەگۆڕن، نەک دراوەکانی ناویان.

CREATE, ALTER, DROPCREATE، ALTER، DROPddl.sqlSQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
-- DDL: build and change the shape of the database
CREATE TABLE student (
  id    INTEGER PRIMARY KEY,
  name  TEXT NOT NULL,
  marks INTEGER
);
ALTER TABLE student ADD COLUMN city TEXT;
SELECT name FROM pragma_table_info('student');
DROP TABLE student;
SELECT COUNT(*) FROM sqlite_schema WHERE type = 'table';
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2-6

CREATE TABLE makes a new table. In SQLite, INTEGER PRIMARY KEY numbers new rows by itself.

CREATE TABLE خشتەیەکی نوێ دروست دەکات. لە SQLiteـدا INTEGER PRIMARY KEY خۆی ژمارە دەداتە ڕیزە نوێیەکان.

Lineدێڕی 7

ALTER TABLE … ADD COLUMN adds a column to an existing table.

ALTER TABLE … ADD COLUMN ستوونێک بۆ خشتەیەکی هەبوو زیاد دەکات.

Lineدێڕی 8

A question to SQLite: which columns does the table have now?

پرسیارێک لە SQLite: خشتەکە ئێستا کام ستوونانەی هەیە؟

Lineدێڕی 9

DROP TABLE removes the table and all its rows.

DROP TABLE خشتەکە و هەموو ڕیزەکانی لادەبات.

SQLite commands: the familiesفەرمانەکانی SQLite: خێزانەکان

DML and DQL: changing and reading rowsDML و DQL: گۆڕین و خوێندنەوەی ڕیزەکان

Definitionپێناسە

The SQL commands that change the data inside tables: INSERT, UPDATE and DELETE. (Some books also put SELECT here; this course lists it as .)

ئەو فەرمانانەی SQL کە دراوەی ناو خشتەکان دەگۆڕن: INSERT، UPDATE و DELETE. (هەندێک کتێب SELECTیش دەخەنە ئێرە؛ ئەم کۆرسە وەک دایدەنێت.)

Definitionپێناسە

The SQL command that reads data without changing it: SELECT.

ئەو فەرمانەی SQL کە دراوە دەخوێنێتەوە بەبێ ئەوەی بیگۆڕێت: SELECT.

INSERT, UPDATE, DELETE, then SELECTINSERT، UPDATE، DELETE، پاشان SELECTdml-dql.sqlSQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
CREATE TABLE student (id INTEGER PRIMARY KEY, name TEXT NOT NULL, marks INTEGER);
-- DML: change the rows inside the tables
INSERT INTO student (name, marks) VALUES ('Aram', 85), ('Shilan', 92), ('Karwan', 78);
UPDATE student SET marks = 80 WHERE name = 'Karwan';
DELETE FROM student WHERE name = 'Aram';
-- DQL: ask a question
SELECT id, name, marks FROM student ORDER BY marks DESC;
SELECT name FROM student WHERE marks >= 90;
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

One INSERT can add several rows.

یەک INSERT دەتوانێت چەند ڕیزێک زیاد بکات.

Lineدێڕی 4

UPDATE changes Karwan's marks from 78 to 80.

UPDATE نمرەکانی Karwan لە ⁦78⁩ـەوە دەگۆڕێت بۆ ⁦80⁩.

Lineدێڕی 5

DELETE removes Aram's row. Always give a WHERE: without it every row is deleted.

DELETE ڕیزی Aram لادەبات. هەمیشە WHERE بنووسە: بەبێ ئەو هەموو ڕیزێک دەسڕدرێتەوە.

Lineدێڕی 7-8

SELECT only reads; it changes nothing.

SELECT تەنها دەخوێنێتەوە؛ هیچ ناگۆڕێت.

فێرکاری SQL - سەرەتاییRawan :: ڕەوان · Kurdish (Sorani)کوردی (سۆرانی) · 16K viewsبینین · 488 likesلایک · Partبەشی 10:30–15:10 (ofلە 21:38)

In Kurdish: how to add, read, filter, change and delete rows with INSERT, SELECT, WHERE, UPDATE and DELETE.

بە کوردی فێر دەبیت چۆن زیاد دەکەیت، دەخوێنیتەوە، دەکەیت، دەگۆڕیت و دەسڕیتەوە بە ، ، ، و .

Kurdish, watch 10:30–15:10: INSERT, SELECT, WHERE, UPDATE, DELETE (SQL Server, same SQL).

بە کوردی، لە ⁦10:30⁩ تا ⁦15:10⁩ سەیر بکە: INSERT، SELECT، WHERE، UPDATE و DELETE (بە ⁦SQL Server⁩، بەڵام هەمان شتە).

SQLite commands: the familiesفەرمانەکانی SQLite: خێزانەکان

DCL: permissions (not in SQLite)DCL: مۆڵەتەکان (لە SQLite نییە)

Definitionپێناسە

The SQL commands that control who may do what in a database: GRANT gives a permission and REVOKE takes it away. has no DCL, because access is controlled by the permissions of the database file.

ئەو فەرمانانەی SQL کە کۆنترۆڵی ئەوە دەکەن کێ بۆی هەیە چی لە بنکەدراوەدا بکات: GRANT مۆڵەتێک دەدات و REVOKE دەیسەنێتەوە. DCLـی نییە، چونکە دەستڕاگەیشتن بە مۆڵەتەکانی فایلی بنکەدراوەکە کۆنترۆڵ دەکرێت.

The slides mention a fourth family, DCL, for GRANT and REVOKE. That is true for MySQL and other client–server databases, which have users with passwords. SQLite has no users at all, so it has no DCL: who may read or change the database is decided by the permissions of the file on the disk.

سلایدەکان ناوی خێزانێکی چوارەم دەهێنن، DCL، بۆ GRANT و REVOKE. ئەمە بۆ MySQL و بنکەدراوە ڕاژەخواز و ڕاژەکارەکانی تر ڕاستە، کە بەکارهێنەری خاوەن تێپەڕەوشەیان هەیە. SQLite هیچ بەکارهێنەرێکی نییە، بۆیە DCLـیشی نییە: ئەوەی کێ دەتوانێت بنکەدراوەکە بخوێنێتەوە یان بیگۆڕێت بە مۆڵەتەکانی فایلەکە لەسەر دیسک دیاری دەکرێت.

GRANT and REVOKE in SQLiteGRANT و REVOKE لە SQLitedcl.sqlSQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
CREATE TABLE student (id INTEGER PRIMARY KEY, name TEXT);
GRANT SELECT ON student TO teacher;
REVOKE SELECT ON student FROM teacher;

SQLite commands: the familiesفەرمانەکانی SQLite: خێزانەکان

TCL: all or nothingTCL: یان هەموو یان هیچ

Definitionپێناسە

The SQL commands that control a group of changes: BEGIN starts the group, COMMIT saves every change in it and ROLLBACK cancels every change in it. SQLite and MySQL both have them.

ئەو فەرمانانەی SQL کە کۆمەڵێک گۆڕانکاری کۆنترۆڵ دەکەن: BEGIN کۆمەڵەکە دەست پێدەکات، COMMIT هەموو گۆڕانکارییەکانی پاشەکەوت دەکات و ROLLBACK هەموویان هەڵدەوەشێنێتەوە. SQLite و MySQL هەردووکیان ئەم فەرمانانەیان هەیە.

The slides stop at DCL, but SQLite has one more family that you will need for real applications. A groups several changes so that they all succeed or all fail together. BEGIN starts the group, COMMIT saves it and ROLLBACK cancels it.

سلایدەکان لە DCLـدا دەوەستن، بەڵام SQLite خێزانێکی تریشی هەیە کە بۆ بەرنامەی ڕاستەقینە پێویستت پێی دەبێت. چەند گۆڕانکارییەک کۆدەکاتەوە بە شێوەیەک کە هەموویان پێکەوە سەردەکەون یان پێکەوە شکست دەهێنن. BEGIN کۆمەڵەکە دەست پێدەکات، COMMIT پاشەکەوتی دەکات و ROLLBACK هەڵیدەوەشێنێتەوە.

A cancelled deleteسڕینەوەیەکی هەڵوەشاوەtcl.sqlSQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
CREATE TABLE student (id INTEGER PRIMARY KEY, name TEXT);
INSERT INTO student (name) VALUES ('Aram'), ('Shilan');
BEGIN;
DELETE FROM student;
SELECT COUNT(*) FROM student;
ROLLBACK;
SELECT COUNT(*) FROM student;
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 4

Inside the transaction, every row is deleted…

لەناو مامەڵەکەدا، هەموو ڕیزێک دەسڕدرێتەوە…

Lineدێڕی 6

…and ROLLBACK brings them back.

…و ROLLBACK دەیانگەڕێنێتەوە.

What is a Database Transaction? Be ACID compliant!Be A Better Dev · Englishئینگلیزی · 109K viewsبینین · 2.6K likesلایک

Learn what a transaction is: several changes that must all succeed or all fail together, shown with a bank account example.

فێر دەبیت چییە: چەند گۆڕانکارییەک کە دەبێت یان هەموویان پێکەوە سەرکەون یان هەموویان پێکەوە شکست بهێنن، بە نموونەی هەژمارێکی بانک.

Whole video: transactions as all-or-nothing groups of changes.

هەموو ڤیدیۆکە: وەک کۆمەڵە گۆڕانکارییەک کە یان هەمووی جێبەجێ دەبێت یان هیچی.

Upper case and lower caseپیتی گەورە و پیتی بچووک

The slide's "important point" reads: "SQLite is case insensitive. Like GLOB and glob have different meanings in an SQLite statement." The two sentences contradict each other, and the second one is wrong. Here is what is really true, checked with SQLite 3.51:

«خاڵە گرنگەکە»ی سلایدەکە دەڵێت: «SQLite هەستیار نییە بە پیتی گەورە و بچووک. وەک ئەوەی GLOB و glob لە ڕستەیەکی SQLiteـدا دوو واتای جیاوازیان هەیە.» دوو ڕستەکە دژی یەکن و دووەمیان هەڵەیە. ئەمە ئەوەیە کە بە ڕاستی ڕاستە، بە ⁦SQLite 3.51⁩ پشکنراوە:

First, the two pattern operators. LIKE and GLOB are both SQLite for matching text patterns. In LIKE, % means "any characters" and _ means "exactly one character". In GLOB, * means "any characters", ? means "exactly one character" and [ ] means "one of these characters".

سەرەتا، دوو شێوە. LIKE و GLOB هەردووکیان SQLiteـن بۆ گونجاندنی شێوەی دەق. لە LIKEـدا % واتە «هەر نووسەیەک، بە هەر ژمارەیەک» و _ واتە «ڕێک یەک نووسە». لە GLOBـدا * واتە «هەر نووسەیەک، بە هەر ژمارەیەک»، ? واتە «ڕێک یەک نووسە» و [ ] واتە «یەکێک لەم نووسانە».

Case sensitivity in SQLite.هەستیاری بە پیتی گەورە و بچووک لە SQLite.
Part of the SQLبەشێک لە SQLCase-sensitive?هەستیارە بە پیت؟Exampleنموونە
Keywords (SELECT, FROM, GLOB…) (SELECT، FROM، GLOB…)Noنەخێرselect = SELECT, glob = GLOB
Table and column namesناوی خشتە و ستوونNo (in SQLite)نەخێر (لە SQLite)FROM STUDENT = FROM student
Text compared with =دەق کە بە = بەراورد دەکرێتYesبەڵێ'aram' = 'Aram' is false
LIKE patterns (%, _)شێوەکانی LIKE (%، _)No, for the English letters A–Zنەخێر، بۆ پیتە ئینگلیزییەکانی ⁦A–Z⁩'abc' LIKE 'A%' is true
GLOB patterns (*, ?, [ ])شێوەکانی GLOB (*، ?، [ ])Yesبەڵێ'abc' GLOB 'A*' is false
Testing the rulesتاقیکردنەوەی یاساکانcase.sqlSQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
CREATE TABLE student (id INTEGER PRIMARY KEY, name TEXT);
INSERT INTO student (name) VALUES ('Aram'), ('aram'), ('Hana');
SELECT name FROM student;
select NAME from STUDENT;
SELECT name FROM student WHERE name = 'aram';
SELECT name FROM student WHERE name LIKE 'a%';
SELECT name FROM student WHERE name GLOB 'a*';
SELECT name FROM student WHERE name glob 'a*';
SELECT name FROM student WHERE name = 'aram' COLLATE NOCASE;
SELECT 'abc' GLOB 'A*', 'abc' glob 'a*', 'abc' LIKE 'A%';
SELECT 'Hana' GLOB 'H?na', 'Aram' LIKE 'A_am', 'Hana' GLOB 'H[aeiou]na';
SELECT 'Ä' LIKE 'ä', 'A' LIKE 'a';
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3-4

Keywords and names in any case: the same result.

و ناو بە هەر شێوەیەک: هەمان ئەنجام.

Lineدێڕی 5

= compares text exactly: only aram.

= دەق بە وردی بەراورد دەکات: تەنها aram.

Lineدێڕی 6

LIKE ignores case for A–Z; % means "any characters".

LIKE گوێ بە پیتی گەورە و بچووکی ⁦A–Z⁩ نادات؛ % واتە «هەر نووسەیەک».

Lineدێڕی 7-8

GLOB respects case; * means "any characters". GLOB and glob are the same operator.

GLOB ڕێز لە پیتی گەورە و بچووک دەگرێت؛ * واتە «هەر نووسەیەک». GLOB و glob هەمان کارپێکەرن.

Lineدێڕی 9

COLLATE NOCASE makes one comparison ignore case.

COLLATE NOCASE یەک بەراورد دەکات بە بێ‌جیاوازی لە نێوان پیتی گەورە و بچووک.

Lineدێڕی 11

? in GLOB = exactly one character (like _ in LIKE); [aeiou] = one of these letters.

? لە GLOB = ڕێک یەک نووسە (وەک _ لە LIKE)؛ [aeiou] = یەکێک لەم پیتانە.

Lineدێڕی 12

LIKE ignores case only for A–Z: Ä and ä are different.

LIKE تەنها بۆ ⁦A–Z⁩ گوێ بە گەورە و بچووکی نادات: Ä و ä جیاوازن.

Quick checkپشکنینی خێراThe table has the names Aram, aram and Hana. Which condition finds both Aram and aram?خشتەکە ناوەکانی Aram، aram و Hanaـی تێدایە. کام مەرج هەردوو Aram و aram دەدۆزێتەوە؟

  • So what is safe? Write every SQL keyword in CAPITALS, and write table and column names exactly as you created them. SQLite would forgive a different case, but MySQL on Linux treats table names as case-sensitive.
  • Remember PHP as well: PHP variable names are case-sensitive ($name and $Name are two different variables), while PHP keywords and function names are not. When in doubt, pick one style and keep it on every page.
  • کەواتە چی سەلامەتە؟ هەموو SQL بە پیتی گەورە بنووسە و ناوی خشتە و ستوونەکان ڕێک وەک ئەوەی دروستت کردوون بنووسە. SQLite لە شێوەیەکی جیاواز خۆش دەبێت، بەڵام MySQL لەسەر Linux ناوی خشتەکان بە دادەنێت.
  • PHPـیش لەبیر مەکە: ناوی گۆڕاوەکانی PHP هەستیارن بە پیتی گەورە و بچووک ($name و $Name دوو گۆڕاوی جیاوازن)، بەڵام و ناوی کردارەکانی PHP هەستیار نین. ئەگەر دوودڵ بوویت، یەک شێواز هەڵبژێرە و لە هەموو لاپەڕەیەکدا پێوەی پابەند بە.
types.sqlSQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
CREATE TABLE t (n INTEGER);
INSERT INTO t VALUES (42), ('42'), ('hello');
SELECT n, typeof(n) FROM t;
CREATE TABLE t2 (n INTEGER) STRICT;
INSERT INTO t2 VALUES ('hello');

phpLiteAdmin: a web tool for SQLitephpLiteAdmin: ئامرازێکی وێبی بۆ SQLite

Definitionپێناسە

A small web tool, written in PHP, for managing database files in the browser, much as does for MySQL.

ئامرازێکی وێبیی بچووکە، بە PHP نووسراوە، بۆ بەڕێوەبردنی فایلەکانی بنکەدراوەی لە ڕێگەی تۆڕگەڕەوە، هەر وەک بۆ MySQL.

phpLiteAdmin is a web-based tool for managing SQLite databases. It is written in PHP and supports SQLite 3 (and the very old SQLite 2). It needs no installation: copy its one PHP file into your web folder and open it in the browser. Everything it can do is there from the start. It is the same idea as phpMyAdmin: one is for MySQL, the other is for SQLite, so if you can use one, you can use the other.

phpLiteAdmin ئامرازێکی وێبییە بۆ بەڕێوەبردنی بنکەدراوەکانی SQLite. بە PHP نووسراوە و ⁦SQLite 3⁩ پشتگیری دەکات (و ⁦SQLite 2⁩ـی زۆر کۆنیش). پێویستی بە دامەزراندن نییە: یەک فایلە PHPـەکەی کۆپی بکە بۆ فۆڵدەری وێبەکەت و لە تۆڕگەڕدا بیکەرەوە. هەموو ئەو کارانەی دەتوانێت بیکات لە سەرەتاوە ئامادەن. هەمان بیرۆکەی phpMyAdminـە: یەکێکیان بۆ MySQLـە، ئەوی تر بۆ SQLite، بۆیە ئەگەر یەکێکیان بەکاربهێنیت دەتوانیت ئەوی تریش بەکاربهێنیت.

What you can do with it

چی دەتوانیت پێی بکەیت

  • Create and drop databases
  • Create, rename and drop tables
  • Add, edit and delete rows
  • Run any SQL you like
  • Import and export data
  • See the structure of a table
  • دروستکردن و سڕینەوەی بنکەدراوە
  • دروستکردن، ناوگۆڕین و سڕینەوەی خشتە
  • زیادکردن، دەستکاریکردن و سڕینەوەی ڕیز
  • جێبەجێکردنی هەر SQLێک کە بتەوێت
  • هاوردەکردن و هەناردەکردنی دراوە
  • بینینی پێکهاتەی خشتەیەک
Quick checkپشکنینی خێراWhat is phpLiteAdmin?phpLiteAdmin چییە؟

Using SQLite from PHPبەکارهێنانی SQLite لە PHPـەوە

PHP talks to SQLite through , exactly as it talks to MySQL. Only the connection line is different: instead of a host, a user and a password you give a path to a file. If the file does not exist, SQLite creates it.

PHP لە ڕێگەی قسە لەگەڵ SQLite دەکات، ڕێک وەک چۆن قسە لەگەڵ MySQL دەکات. تەنها دێڕی پەیوەندییەکە جیاوازە: لە جیاتی ڕاژەکار و بەکارهێنەر و تێپەڕەوشە، ڕێڕەوی فایلێک دەدەیت. ئەگەر فایلەکە نەبێت، SQLite دروستی دەکات.

A complete example: create, insert, selectنموونەیەکی تەواو: دروستکردن، زیادکردن، هەڵبژاردنschool.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
// 1. Open the database file (SQLite creates it if it does not exist).
//    No host, no username, no password: just a path to a file.
$db = new PDO('sqlite:' . __DIR__ . '/school.db');
$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);

// 2. DDL: create the table (only if it is not there yet)
$db->exec("CREATE TABLE IF NOT EXISTS student (
    id    INTEGER PRIMARY KEY,
    name  TEXT NOT NULL,
    marks INTEGER
)");

// 3. DML: insert rows with a prepared statement
$stmt = $db->prepare("INSERT INTO student (name, marks) VALUES (?, ?)");
foreach ([["Aram", 85], ["Shilan", 92], ["Karwan", 78]] as [$name, $marks]) {
    $stmt->execute([$name, $marks]);
}
echo "Last new id: ", $db->lastInsertId(), "\n";

// 4. DQL: read the rows back
foreach ($db->query("SELECT id, name, marks FROM student ORDER BY marks DESC") as $row) {
    echo $row['id'], " | ", $row['name'], " | ", $row['marks'], "\n";
}

clearstatcache();
echo "The whole database is one file of ", filesize(__DIR__ . '/school.db'), " bytes\n";
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 4

'sqlite:' . __DIR__ . '/school.db': the database is the file school.db in the same folder as the script.

'sqlite:' . __DIR__ . '/school.db': بنکەدراوەکە فایلی school.dbـە لە هەمان فۆڵدەری دەسنووسەکەدا.

Lineدێڕی 8-12

DDL. IF NOT EXISTS lets you run the script again without an error.

DDL. IF NOT EXISTS ڕێگەت پێدەدات دەسنووسەکە دووبارە کارپێبکەیتەوە بەبێ هەڵە.

Lineدێڕی 15-18

DML with a prepared statement: one prepare(), many execute() calls.

DML بە : یەک prepare()، چەندین بانگکردنی execute().

Lineدێڕی 19

lastInsertId() gives the id SQLite chose for the last row.

lastInsertId() ئەو idـیە دەدات کە SQLite بۆ دوایین ڕیز هەڵیبژارد.

Lineدێڕی 22-24

DQL: read the rows, highest marks first.

DQL: ڕیزەکان بخوێنەوە، بەرزترین نمرە یەکەم.

Lineدێڕی 26-27

The whole database really is one small file.

هەموو بنکەدراوەکە بە ڕاستی یەک فایلی بچووکە.

Quick checkپشکنینی خێراWhat do you give new PDO(...) to open an SQLite database?بۆ کردنەوەی SQLite چی دەدەیت بە new PDO(...)؟

Using SQLite from PHPبەکارهێنانی SQLite لە PHPـەوە

The SQLite3 class, and SQLite next to MySQLپۆلی ⁦SQLite3⁩ و SQLite لە تەنیشت MySQLـەوە

PHP also has a class only for SQLite, SQLite3. It works well, but PDO is usually the better choice, because the same code style works for MySQL too.

PHP هەروەها تایبەت بە SQLite هەیە، SQLite3. باش کار دەکات، بەڵام PDO زۆرجار هەڵبژاردنی باشترە، چونکە هەمان شێوازی کۆد بۆ MySQLـیش کار دەکات.

The same database with the SQLite3 classهەمان بنکەدراوە بە کلاسی ⁦SQLite3⁩sqlite3-class.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
// The other way: PHP's SQLite3 class (works only with SQLite)
$db = new SQLite3(__DIR__ . '/school.db');

$stmt = $db->prepare("SELECT name, marks FROM student WHERE marks > :min ORDER BY name");
$stmt->bindValue(':min', 80, SQLITE3_INTEGER);
$result = $stmt->execute();

while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
    echo $row['name'], ": ", $row['marks'], "\n";
}
$db->close();
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 5-6

Named placeholders and bindValue() with a type constant.

ناودار و bindValue() لەگەڵ نەگۆڕێکی جۆر.

Lineدێڕی 9

fetchArray(SQLITE3_ASSOC) returns the next row, or false at the end.

fetchArray(SQLITE3_ASSOC) ڕیزی دواتر دەگەڕێنێتەوە، یان false لە کۆتاییدا.

The same PHP skills, two kinds of database.هەمان شارەزاییەکانی PHP، دوو جۆر بنکەدراوە.
MySQL / MariaDBSQLite
PDO connectionپەیوەندیی PDOnew PDO('mysql:host=localhost;dbname=mydb;charset=utf8mb4', 'root', '')new PDO('sqlite:' . __DIR__ . '/school.db')
Auto numberingژمارەدانی خۆکارid INT AUTO_INCREMENT PRIMARY KEYid INTEGER PRIMARY KEY
Users and GRANTبەکارهێنەر و GRANTyesبەڵێno: file permissionsنەخێر: مۆڵەتەکانی فایل
Admin toolئامرازی بەڕێوەبردنphpMyAdminphpLiteAdmin
PHP extensionsپاشکۆکانی PHPmysqli, pdo_mysqlpdo_sqlite, sqlite3
Does your PHP have SQLite?ئایا PHPـەکەت SQLiteی هەیە؟check.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
var_dump(extension_loaded('pdo_sqlite'));
var_dump(extension_loaded('sqlite3'));
print_r(PDO::getAvailableDrivers());

Exercisesڕاهێنانەکان

Exerciseڕاهێنان1. Your first SQLite page١. یەکەم لاپەڕەی SQLiteـت

Write students.php: open (or create) school.db with PDO, make a student table (id, name, marks) if it does not exist, add three students with a prepared statement, and print, as an HTML list, the students with 80 marks or more, sorted by name.

students.php بنووسە: بە PDO فایلی school.db بکەرەوە (یان دروستی بکە)، ئەگەر خشتەی student (id، name، marks) نەبێت دروستی بکە، سێ قوتابی بە زیاد بکە و وەک لیستێکی HTML ئەو قوتابیانە چاپ بکە کە ⁦80⁩ نمرە یان زیاتریان هەیە، بەپێی ناو ڕیزکراو.

Hintئاماژە

Start from school.php in this lecture, and add WHERE marks >= ? and ORDER BY name.

لە school.phpـی ئەم وانەیەوە دەست پێبکە و WHERE marks >= ? و ORDER BY name زیاد بکە.

Show answerوەڵامەکە پیشان بدە
students.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
// students.php - create, fill and read an SQLite database with PDO
$db = new PDO('sqlite:' . __DIR__ . '/school.db');     // opens the file, or creates it
$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);

// 1. DDL: the table, only if it does not exist yet
$db->exec("CREATE TABLE IF NOT EXISTS student (
    id    INTEGER PRIMARY KEY,
    name  TEXT NOT NULL,
    marks INTEGER
)");

// 2. DML: add three students, but only into an empty table (so a refresh adds nothing twice)
if ($db->query("SELECT COUNT(*) FROM student")->fetchColumn() == 0) {
    $stmt = $db->prepare("INSERT INTO student (name, marks) VALUES (?, ?)");
    foreach ([["Aram", 85], ["Shilan", 92], ["Karwan", 78]] as [$name, $marks]) {
        $stmt->execute([$name, $marks]);
    }
}

// 3. DQL: students with 80 marks or more, sorted by name
$stmt = $db->prepare("SELECT name, marks FROM student WHERE marks >= ? ORDER BY name");
$stmt->execute([80]);

echo "<ul>\n";
foreach ($stmt->fetchAll() as $row) {
    echo "  <li>", htmlspecialchars($row['name']), " (", (int) $row['marks'], ")</li>\n";
}
echo "</ul>\n";
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

Opens school.db, or creates it if it does not exist.

school.db دەکاتەوە، یان ئەگەر نەبێت دروستی دەکات.

Lineدێڕی 7-11

DDL: IF NOT EXISTS makes the script safe to run again.

DDL: IF NOT EXISTS وا دەکات دەسنووسەکە بە سەلامەتی دووبارە کار بکاتەوە.

Lineدێڕی 14-19

DML with a prepared statement, only when the table is still empty, so a refresh does not add the students twice.

DML بە ، تەنها کاتێک خشتەکە هێشتا بەتاڵە، بۆ ئەوەی refresh قوتابییەکان دوو جار زیاد نەکات.

Lineدێڕی 22-23

DQL: the minimum mark is a value, so it goes into a placeholder.

DQL: کەمترین نمرە نرخێکە، بۆیە دەچێتە ناو .

Lineدێڕی 27

Escape the name before printing it into HTML.

ناوەکە پێش چاپکردن لەناو HTMLـدا بێزیان بکە.

Exerciseڕاهێنان2. LIKE or GLOB?٢. LIKE یان GLOB؟

The table student contains the names Aram, aram and Hana. Without running anything, write what each query returns: (a) WHERE name = 'aram', (b) WHERE name LIKE 'a%', (c) WHERE name GLOB 'a*', (d) where name glob 'A*'.

خشتەی student ناوەکانی Aram، aram و Hanaی تێدایە. بەبێ کارپێکردنی هیچ شتێک، بنووسە هەر پرسێک چی دەگەڕێنێتەوە: (أ) WHERE name = 'aram'، (ب) WHERE name LIKE 'a%'، (ج) WHERE name GLOB 'a*'، (د) where name glob 'A*'.

Show answerوەڵامەکە پیشان بدە
  • (a) aram only: = is case-sensitive.
  • (b) Aram and aram: LIKE ignores case for A–Z.
  • (c) aram only: GLOB is case-sensitive.
  • (d) Aram only: glob is the same operator as GLOB, and A* needs a capital A.
  • (أ) تەنها aram: = هەستیارە بە پیتی گەورە و بچووک.
  • (ب) Aram و aram: LIKE گوێ بە گەورە و بچووکی ⁦A–Z⁩ نادات.
  • (ج) تەنها aram: GLOB هەستیارە بە پیتی گەورە و بچووک.
  • (د) تەنها Aram: glob هەمان کارپێکەری GLOBـە و A* پیتی Aـی گەورەی پێویستە.

(a)–(c) are in the tested output of the case-sensitivity section; (d) follows from the same rules.

(أ)–(ج) لە دەرخستە تاقیکراوەکەی بەشی هەستیاری بە پیتدان؛ (د) لە هەمان یاساکانەوە دەردەچێت.

Exerciseڕاهێنان3. Which family?٣. کام خێزان؟

Name the family (DDL, DML, DQL, DCL or TCL) of each command, and say whether SQLite accepts it: ALTER TABLE student ADD COLUMN city TEXT, INSERT INTO student …, SELECT * FROM student, GRANT SELECT ON student TO teacher, ROLLBACK.

خێزانی هەر فەرمانێک بنووسە (DDL، DML، DQL، DCL یان TCL) و بڵێ ئایا SQLite وەری دەگرێت: ALTER TABLE student ADD COLUMN city TEXT، INSERT INTO student …، SELECT * FROM student، GRANT SELECT ON student TO teacher، ROLLBACK.

Show answerوەڵامەکە پیشان بدە
CommandفەرمانFamilyخێزانIn SQLite?لە SQLite؟
ALTER TABLE … ADD COLUMNDDLyesبەڵێ
INSERT INTO …DMLyesبەڵێ
SELECT …DQL (DML in many books)DQL (لە زۆر کتێبدا DML)yesبەڵێ
GRANT …DCLno: syntax errorنەخێر:
ROLLBACKTCLyes (inside a transaction)بەڵێ (لەناو مامەڵەیەکدا)

Summary and reviewپوختە و پێداچوونەوە

  • SQLite is a small, serverless, zero-configuration, self-contained database engine that keeps a whole relational database in one cross-platform file.
  • It is a library linked into your program (in PHP: pdo_sqlite, sqlite3) and reads the file directly. MySQL, by contrast, is a separate server program.
  • D. Richard Hipp designed it in 2000; it is in the public domain. UnQLite is a different product, by Symisc Systems.
  • SQL families: DDL (CREATE, ALTER, DROP), DML (INSERT, UPDATE, DELETE), DQL (SELECT), DCL (GRANT, REVOKE: not in SQLite), TCL (BEGIN, COMMIT, ROLLBACK).
  • Keywords and names are not case-sensitive; = and GLOB are; LIKE is not (for A–Z). GLOB and glob are the same.
  • phpLiteAdmin is to SQLite what phpMyAdmin is to MySQL: one PHP file; protect it with a strong password.
  • SQLite بزوێنەرێکی بچووک، بێ‌ڕاژەکار، بێ ڕێکخستن و خۆبەسەندی بنکەدراوەیە کە هەموو لە یەک فایلی فرەسەکۆدا هەڵدەگرێت.
  • کتێبخانەیەکە کە دەبەسترێتەوە بە بەرنامەکەتەوە (لە PHPـدا: pdo_sqlite، sqlite3) و ڕاستەوخۆ فایلەکە دەخوێنێتەوە. بە پێچەوانەوە MySQL بەرنامەیەکی ڕاژەکاری جیایە.
  • ⁦D. Richard Hipp⁩ لە ٢٠٠٠دا دیزاینی کرد؛ . UnQLite بەرهەمێکی ترە، هی ⁦Symisc Systems⁩.
  • خێزانەکانی ⁦SQL: DDL (CREATE⁩، ALTER، DROP)، ⁦DML (INSERT⁩، UPDATE، DELETE)، ⁦DQL (SELECT)⁩، ⁦DCL (GRANT⁩، REVOKE: لە SQLite نییە)، ⁦TCL (BEGIN⁩، COMMIT، ROLLBACK).
  • و ناوەکان هەستیار نین بە پیتی گەورە و بچووک؛ = و GLOB هەستیارن؛ LIKE هەستیار نییە (بۆ ⁦A–Z⁩). GLOB و glob هەمان شتن.
  • phpLiteAdmin بۆ SQLite ئەوەیە کە phpMyAdmin بۆ MySQL: یەک فایلی PHP؛ بە تێپەڕەوشەیەکی بەهێز بیپارێزە.
Review questionsپرسیارەکانی پێداچوونەوە
Where does SQLite keep a whole database?SQLite هەموو بنکەدراوەیەک لە کوێ هەڵدەگرێت؟

In one single cross-platform disk file.

لە یەک فایلی دیسکی فرەسەکۆدا.

What does serverless mean here?بێ‌ڕاژەکار لێرەدا واتای چییە؟

SQLite does not require a separate server process or system to operate.

SQLite پێویستی بە پرۆسە یان سیستەمێکی ڕاژەکاری جیا نییە بۆ کارکردن.

Which three commands belong to DDL?کام سێ فەرمان سەر بە DDLـن؟

CREATE, ALTER and DROP: they define the shape of the database.

CREATE، ALTER و DROP: شێوەی بنکەدراوە پێناسە دەکەن.

Which commands belong to DML and DQL?کام فەرمانانە سەر بە DML و DQLـن؟

DML: INSERT, UPDATE, DELETE. DQL: SELECT.

⁦DML: INSERT⁩، UPDATE، ⁦DELETE. DQL: SELECT⁩.

Who designed SQLite, and when?کێ SQLiteی دیزاین کرد و کەی؟

D. Richard Hipp, in 2000, so that no administration would be needed.

⁦D. Richard Hipp⁩، لە ٢٠٠٠دا، بۆ ئەوەی هیچ بەڕێوەبردنێک پێویست نەبێت.

What is phpLiteAdmin?phpLiteAdmin چییە؟

A web-based SQLite admin tool written in PHP, needing no installation (but it needs PHP with SQLite and a strong password).

ئامرازێکی وێبیی بەڕێوەبردنی SQLite کە بە PHP نووسراوە و پێویستی بە دامەزراندن نییە (بەڵام پێویستی بە PHP لەگەڵ SQLite و تێپەڕەوشەیەکی بەهێز هەیە).

Does SQLite support GRANT and REVOKE?ئایا SQLite پشتگیری GRANT و REVOKE دەکات؟

No. SQLite has no users, so it has no DCL; access is controlled by the file's permissions.

نەخێر. SQLite هیچ بەکارهێنەرێکی نییە، بۆیە DCLـی نییە؛ دەستڕاگەیشتن بە مۆڵەتەکانی فایلەکە کۆنترۆڵ دەکرێت.

How does a PHP connection to SQLite differ from one to MySQL?پەیوەندیی PHP بە SQLiteـەوە چ جیاوازییەکی لەگەڵ پەیوەندی بە MySQLـەوە هەیە؟

The PDO DSN is sqlite: plus a file path; there is no host, user or password. The rest of the PDO code is the same.

DSNـی PDO بریتییە لە sqlite: لەگەڵ ڕێڕەوی فایلێک؛ هیچ host، user یان passwordـێک نییە. باقی کۆدی PDO هەمان شتە.

Videoڤیدیۆ

Watch a videoسەیری ڤیدیۆیەک بکە

A video that viewers liked a lot and praised in their comments, chosen for this lesson.ڤیدیۆیەک کە بینەران زۆریان پێ خۆش بووە و لە کۆمێنتەکانیاندا ستایشیان کردووە، بۆ ئەم وانەیە هەڵبژێردراوە.

SQLite Introduction - Beginners Guide to SQL and DatabasesCaleb Curry · Englishئینگلیزی · 215K viewsبینین · 3.7K likesلایک · Partبەشی 0:00–15:21 (ofلە 21:49)

A calm first look at SQLite: what it is, why it is used, and how to create tables, add, read, change and delete rows.

یەکەم ناساندنێکی ئارام بۆ : چییە، بۆچی بەکاردێت و چۆن دروست دەکەیت و زیاد دەکەیت، دەخوێنیتەوە، دەگۆڕیت و دەسڕیتەوە.

Watch 0:00–15:21: what SQLite is, then tables and rows; joins come later.

لە ⁦0:00⁩ تا ⁦15:21⁩ سەیر بکە: چییە، پاشان و ؛ JOIN دواتر دێت.

Lesson complete!وانەکە تەواو بوو!

Well done. Review the key terms, then go on to the next lesson.دەستخۆش. سەیرێکی زاراوە سەرەکییەکان بکەرەوە، پاشان بڕۆ بۆ وانەی داهاتوو.

Key termsزاراوە سەرەکییەکان

Next lessonوانەی داهاتوو

Cookiesکووکییەکان

References and further readingسەرچاوەکان و خوێندنەوەی زیاتر

This lecture is a first edition. The Kurdish text and terminology are waiting for review by Kurdish IT teachers.ئەم وانەیە چاپی یەکەمە. دەقە کوردییەکە و زاراوەکانی چاوەڕێی پێداچوونەوەی مامۆستایانی کوردی بواری IT ن.