SlideShare a Scribd company logo
1 of 19
Advance Mobile Application
Development
Local Database
Dr. Mazin Alkathiri
IT Department
Seiyun University
2023-2024
Flutter – Database Concepts
• Flutter provides many advanced packages to work with databases.
The most important packages are:
• sqflite – Used to access and manipulate SQLite database, and
• firebase_database – Used to access and manipulate cloud hosted
NoSQL database from Google.
SQLite
• SQLite database is the de-facto and standard SQL based embedded database engine.
• It is small and time-tested database engine.
• sqflite package provides a lot of functionality to work efficiently with SQLite database.
• It provides standard methods to manipulate SQLite database engine.
• The core functionality provided by sqflite package is as follows:
• Create / Open (openDatabase method) a SQLite database.
• Execute SQL statement (execute method) against SQLite database.
• Advanced query methods (query method) to reduce to code required to query and get information
from SQLite database.
• SQLite doesn’t need a server or backend code, all the info is saved to a
computer file within the device, or we will say it’s native to storage.
• SQLite is used by literally millions of applications with literally billions and
billions of deployments. SQLite is the most widely deployed database
engine in the world today.
SQLite Browser
SQLite is a very popular database - it is free and fast and small SQLite
Browser allows us to directly manipulate SQLite files
http://sqlitebrowser.org/
SQLite is embedded in Python and a number of other languages
Installing SQLite Plugin to Flutter
Define the database variable DB
Future<Database?> get db async {
if (_db == null) {
_db = await initalDb();
return _db;
} else {
return _db;
}
}
initalDb() async {
String databasepath = await getDatabasesPath();
String path = join(databasepath, 'mazdb.db');
Database mydb = await openDatabase(
path, onCreate: _onCreate, version: 2, onUpgrade: _onUpgrade);
return mydb;
}
Get the default
databases location.
Open the database at a
given path
version (optional) specifies the schema version of the database being opened. This is used to
decide whether to call onCreate, onUpgrade, and onDowngrade
The optional callbacks are called in the following order:
1.onConfigure
2.onCreate or onUpgrade or onDowngrade
3.onOpen
_onCreate(Database db, int version) async {
await db.execute('''
CREATE TABLE "notes"(
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"note" TEXT NOT NULL
)
''');
await db.execute('''
CREATE TABLE "users"(
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"user_name" TEXT NOT NULL,
"user_password" TEXT NOT NULL
)
''');
print("======onCreat database and tables ================");
}
_onUpgrade(Database db, int oldversion, int newversion) async {
await db.execute('''
CREATE TABLE "products"(
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"pro_name" TEXT NOT NULL,
"pro_type" TEXT NOT NULL,
"pro_desc" TEXT NOT NULL
)
''');
print("onUpgrae =========================");
}
// SELECT
readData(String sql) async{
Database? mydb = await db;
List<Map> response = await mydb!.rawQuery(sql);
return response;
}
SqlDb sqlDb=SqlDb();
child: MaterialButton(
color: Colors.blue,
onPressed:() async{
List<Map> response= await sqlDb.readData("SELECT * FROM 'notes'");
print(response);
},
child:Text("Read data"),
),
// INSERT
insertData(String sql) async{
Database? mydb = await db;
int response = await mydb!.rawInsert(sql);
return response;
}
SqlDb sqlDb=SqlDb();
child: MaterialButton(
color: Colors.amber,
onPressed:() async{
int response = await
sqlDb.insertData("INSERT INTO 'notes' ('note') VALUES ('my note is ..... some text over here ')");
print(response);
},
child:Text("Insert data"),
),
// UPDATE
updateData(String sql) async{
Database? mydb = await db;
int response = await mydb!.rawUpdate(sql);
return response;
}
SqlDb sqlDb=SqlDb();
child: MaterialButton(
color: Colors.blue,
onPressed:() async{
int response= await sqlDb.updateData("UPDATE 'notes' SET note = 'not two' WHERE id = 2");
print(response);
},
child:Text("update data"),
),
// DELETE
deleteData(String sql) async{
Database? mydb = await db;
int response = await mydb!.rawDelete(sql);
return response;
}
SqlDb sqlDb=SqlDb();
child: MaterialButton(
color: Colors.blue,
onPressed:() async{
int response= await sqlDb.deleteData("DELETE FROM 'notes' WHERE id=1");
print(response);
},
child:Text("Delete data"),

More Related Content

Similar to Advance Mobile Application Development class 01

Data Handning with Sqlite for Android
Data Handning with Sqlite for AndroidData Handning with Sqlite for Android
Data Handning with Sqlite for Android
Jakir Hossain
 

Similar to Advance Mobile Application Development class 01 (20)

Jdbc
JdbcJdbc
Jdbc
 
MySQL Baics - Texas Linxufest beginners tutorial May 31st, 2019
MySQL Baics - Texas Linxufest beginners tutorial May 31st, 2019MySQL Baics - Texas Linxufest beginners tutorial May 31st, 2019
MySQL Baics - Texas Linxufest beginners tutorial May 31st, 2019
 
Access Data from XPages with the Relational Controls
Access Data from XPages with the Relational ControlsAccess Data from XPages with the Relational Controls
Access Data from XPages with the Relational Controls
 
Data Handning with Sqlite for Android
Data Handning with Sqlite for AndroidData Handning with Sqlite for Android
Data Handning with Sqlite for Android
 
Sqlmap
SqlmapSqlmap
Sqlmap
 
Sql lite android
Sql lite androidSql lite android
Sql lite android
 
Andriy Zrobok "MS SQL 2019 - new for Big Data Processing"
Andriy Zrobok "MS SQL 2019 - new for Big Data Processing"Andriy Zrobok "MS SQL 2019 - new for Big Data Processing"
Andriy Zrobok "MS SQL 2019 - new for Big Data Processing"
 
DjangoCon 2010 Scaling Disqus
DjangoCon 2010 Scaling DisqusDjangoCon 2010 Scaling Disqus
DjangoCon 2010 Scaling Disqus
 
Handling Database Deployments
Handling Database DeploymentsHandling Database Deployments
Handling Database Deployments
 
Automated Database Sanitization with AWS
Automated Database Sanitization with AWSAutomated Database Sanitization with AWS
Automated Database Sanitization with AWS
 
MySQL Cluster Basics
MySQL Cluster BasicsMySQL Cluster Basics
MySQL Cluster Basics
 
Database connectivity in python
Database connectivity in pythonDatabase connectivity in python
Database connectivity in python
 
JDBC Part - 2
JDBC Part - 2JDBC Part - 2
JDBC Part - 2
 
JDBC Connectivity Model
JDBC Connectivity ModelJDBC Connectivity Model
JDBC Connectivity Model
 
Session 24 - JDBC, Intro to Enterprise Java
Session 24 - JDBC, Intro to Enterprise JavaSession 24 - JDBC, Intro to Enterprise Java
Session 24 - JDBC, Intro to Enterprise Java
 
Building node.js applications with Database Jones
Building node.js applications with Database JonesBuilding node.js applications with Database Jones
Building node.js applications with Database Jones
 
Jdbc
JdbcJdbc
Jdbc
 
Introduction to firebidSQL 3.x
Introduction to firebidSQL 3.xIntroduction to firebidSQL 3.x
Introduction to firebidSQL 3.x
 
AppFabric Velocity
AppFabric VelocityAppFabric Velocity
AppFabric Velocity
 
TDC2016POA | Trilha Cloud Computing - Microsoft Azure ? From Zero To Hero!
TDC2016POA | Trilha Cloud Computing - Microsoft Azure ? From Zero To Hero!TDC2016POA | Trilha Cloud Computing - Microsoft Azure ? From Zero To Hero!
TDC2016POA | Trilha Cloud Computing - Microsoft Azure ? From Zero To Hero!
 

More from Dr. Mazin Mohamed alkathiri

More from Dr. Mazin Mohamed alkathiri (20)

OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Advance Mobile Application Development class 05
Advance Mobile Application Development class 05Advance Mobile Application Development class 05
Advance Mobile Application Development class 05
 
ESSENTIAL of (CS/IT/IS) class 05 (Software concepts)
ESSENTIAL of (CS/IT/IS) class 05 (Software concepts)ESSENTIAL of (CS/IT/IS) class 05 (Software concepts)
ESSENTIAL of (CS/IT/IS) class 05 (Software concepts)
 
OS-operating systems- ch03
OS-operating systems- ch03OS-operating systems- ch03
OS-operating systems- ch03
 
OS-operating systems - ch02 - part-2-2024
OS-operating systems - ch02 - part-2-2024OS-operating systems - ch02 - part-2-2024
OS-operating systems - ch02 - part-2-2024
 
Advance Mobile Application Development class 04
Advance Mobile Application Development class 04Advance Mobile Application Development class 04
Advance Mobile Application Development class 04
 
Advance Mobile Application Development class 03
Advance Mobile Application Development class 03Advance Mobile Application Development class 03
Advance Mobile Application Development class 03
 
Advance Mobile Application Development class 02-B
Advance Mobile Application Development class 02-BAdvance Mobile Application Development class 02-B
Advance Mobile Application Development class 02-B
 
OS-ch02-part-1-2024.ppt
OS-ch02-part-1-2024.pptOS-ch02-part-1-2024.ppt
OS-ch02-part-1-2024.ppt
 
Advance Mobile Application Development class 02
Advance Mobile Application Development class 02Advance Mobile Application Development class 02
Advance Mobile Application Development class 02
 
ESSENTIAL of (CS/IT/IS) class 03-04 (NUMERIC SYSTEMS)
ESSENTIAL of (CS/IT/IS) class 03-04 (NUMERIC SYSTEMS)ESSENTIAL of (CS/IT/IS) class 03-04 (NUMERIC SYSTEMS)
ESSENTIAL of (CS/IT/IS) class 03-04 (NUMERIC SYSTEMS)
 
ESSENTIAL of (CS/IT/IS) class 02 (HCI)
ESSENTIAL of (CS/IT/IS) class 02 (HCI)ESSENTIAL of (CS/IT/IS) class 02 (HCI)
ESSENTIAL of (CS/IT/IS) class 02 (HCI)
 
Seminar
SeminarSeminar
Seminar
 
ESSENTIAL of (CS/IT/IS)
ESSENTIAL of (CS/IT/IS)ESSENTIAL of (CS/IT/IS)
ESSENTIAL of (CS/IT/IS)
 
OS-ch01-2024.ppt
OS-ch01-2024.pptOS-ch01-2024.ppt
OS-ch01-2024.ppt
 
Mobile Application Development class 008
Mobile Application Development class 008Mobile Application Development class 008
Mobile Application Development class 008
 

Recently uploaded

Call Girls in Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in  Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in  Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
AnaAcapella
 

Recently uploaded (20)

HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Call Girls in Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in  Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in  Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdf
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Basic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationBasic Intentional Injuries Health Education
Basic Intentional Injuries Health Education
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17
 

Advance Mobile Application Development class 01

  • 1. Advance Mobile Application Development Local Database Dr. Mazin Alkathiri IT Department Seiyun University 2023-2024
  • 2. Flutter – Database Concepts • Flutter provides many advanced packages to work with databases. The most important packages are: • sqflite – Used to access and manipulate SQLite database, and • firebase_database – Used to access and manipulate cloud hosted NoSQL database from Google.
  • 3. SQLite • SQLite database is the de-facto and standard SQL based embedded database engine. • It is small and time-tested database engine. • sqflite package provides a lot of functionality to work efficiently with SQLite database. • It provides standard methods to manipulate SQLite database engine. • The core functionality provided by sqflite package is as follows: • Create / Open (openDatabase method) a SQLite database. • Execute SQL statement (execute method) against SQLite database. • Advanced query methods (query method) to reduce to code required to query and get information from SQLite database.
  • 4. • SQLite doesn’t need a server or backend code, all the info is saved to a computer file within the device, or we will say it’s native to storage. • SQLite is used by literally millions of applications with literally billions and billions of deployments. SQLite is the most widely deployed database engine in the world today.
  • 5. SQLite Browser SQLite is a very popular database - it is free and fast and small SQLite Browser allows us to directly manipulate SQLite files http://sqlitebrowser.org/ SQLite is embedded in Python and a number of other languages
  • 6.
  • 7.
  • 8.
  • 10. Define the database variable DB
  • 11. Future<Database?> get db async { if (_db == null) { _db = await initalDb(); return _db; } else { return _db; } }
  • 12. initalDb() async { String databasepath = await getDatabasesPath(); String path = join(databasepath, 'mazdb.db'); Database mydb = await openDatabase( path, onCreate: _onCreate, version: 2, onUpgrade: _onUpgrade); return mydb; } Get the default databases location. Open the database at a given path version (optional) specifies the schema version of the database being opened. This is used to decide whether to call onCreate, onUpgrade, and onDowngrade The optional callbacks are called in the following order: 1.onConfigure 2.onCreate or onUpgrade or onDowngrade 3.onOpen
  • 13. _onCreate(Database db, int version) async { await db.execute(''' CREATE TABLE "notes"( "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, "note" TEXT NOT NULL ) '''); await db.execute(''' CREATE TABLE "users"( "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, "user_name" TEXT NOT NULL, "user_password" TEXT NOT NULL ) '''); print("======onCreat database and tables ================"); }
  • 14. _onUpgrade(Database db, int oldversion, int newversion) async { await db.execute(''' CREATE TABLE "products"( "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, "pro_name" TEXT NOT NULL, "pro_type" TEXT NOT NULL, "pro_desc" TEXT NOT NULL ) '''); print("onUpgrae ========================="); }
  • 15.
  • 16. // SELECT readData(String sql) async{ Database? mydb = await db; List<Map> response = await mydb!.rawQuery(sql); return response; } SqlDb sqlDb=SqlDb(); child: MaterialButton( color: Colors.blue, onPressed:() async{ List<Map> response= await sqlDb.readData("SELECT * FROM 'notes'"); print(response); }, child:Text("Read data"), ),
  • 17. // INSERT insertData(String sql) async{ Database? mydb = await db; int response = await mydb!.rawInsert(sql); return response; } SqlDb sqlDb=SqlDb(); child: MaterialButton( color: Colors.amber, onPressed:() async{ int response = await sqlDb.insertData("INSERT INTO 'notes' ('note') VALUES ('my note is ..... some text over here ')"); print(response); }, child:Text("Insert data"), ),
  • 18. // UPDATE updateData(String sql) async{ Database? mydb = await db; int response = await mydb!.rawUpdate(sql); return response; } SqlDb sqlDb=SqlDb(); child: MaterialButton( color: Colors.blue, onPressed:() async{ int response= await sqlDb.updateData("UPDATE 'notes' SET note = 'not two' WHERE id = 2"); print(response); }, child:Text("update data"), ),
  • 19. // DELETE deleteData(String sql) async{ Database? mydb = await db; int response = await mydb!.rawDelete(sql); return response; } SqlDb sqlDb=SqlDb(); child: MaterialButton( color: Colors.blue, onPressed:() async{ int response= await sqlDb.deleteData("DELETE FROM 'notes' WHERE id=1"); print(response); }, child:Text("Delete data"),