uh hello everybody
so this is a basic
uh basic tutorial of sqlitec
uh programming okay so in this video i
want to show you
how to include sqlite in your cc plus
project and how to create a database
how to create table and how to insert
information in that table
and how to select from the table okay
so let's first create a new project
[Music]
so let's just choose console application
[Music]
let's put it just in the desktop
let's name it
[Music]
c plus plus sqlite
[Music]
let's create
so and now
uh go online
excuse me uh and go to
just write sql lite just to
download some packages
[Applause]
and go to download so
just don't leave download this first one
okay
so i have already downloaded it just
click here
[Music]
so that's our project that's
here okay so i have already downloaded
that
sql sqlite library
so let's extract
uh and the desktop
also uh so that's it let's
rename it just name it skill light
and what we do
so open and we put this
uh sqlite
and put it here okay
uh
so now we just include that library that
header okay so what we do
here uh include
[Music]
just use simple quotes
sqlite and sqlite
that's the name of our folder and that's
the name of the header itself okay point
each
okay
so let's remove that line here
so the first thing so that's
your stream let's using
namespace std
and here the first thing we declare
our database so sqlite
3 let's name it
db
[Music]
the second thing i will explain what's
that mean
a scale lighter three
[Music]
statement
[Music]
that's a link also
[Music]
and now let's create our uh
database
[Music]
uh let's connect to our
database sqlite
three open here i want to create
my database okay so the first thing
i declare the name of my database okay
so just me my db for example
and we pass our database address
as argument okay
so let's run and see what can happen
[Music]
ah
so a referenced local variable
okay so yes there is a problem
what i want to do i must include
my c libraries here okay
so just uh right click
and add and add existing items
i go directly to ask here light and i
add
these two point c files okay this
shell and sqlite three okay
because i must include these two files
here
so let's run now
let's run and see what can happen
um
so it's raining there is no excuse me
unable to start
program microsoft debug console and this
probe continue repair
okay okay let's just re-rain it again
so there is no problem everything is
good
so if i open here my folder is
i find that my db here is created
okay and it's empty here okay
uh what i want to do now so
the first thing first i want to
create my uh my table
okay okay so what i do here
is i just sell so
sqlite
three execute okay i use
this function so if you want to
search for for this function
just go to online and search for it
okay so because my my video is just a
basic tutorial
uh so i i won't uh
go through these arguments one by one
okay
so uh the most important thing
excuse me what is my
so i just go with the important things
okay
so the first argument is my database
link
okay so that's my database link
and then i create my table okay
so let's create
table so and if
not exist
if not exists let's name it
i'll go lancer
as my youtube channel name and
let's just create
a int
x one a and t excuse me
in sql the the name is the first and
then the type
okay and x2 another integer
and let's for example
declare a name which is varchar
[Music]
excuse me
let's say so that's our
create table if not exists algoland
answer
i have two integers x1 and x2
and the name
[Music]
so that's it and the next thing
the next thing is
so the next thing is the callback
function we don't need ads
and this also that's and that's the
error message
okay the error message is sometimes
very important to check if your
uh if your request
is running as well okay so
here i input now and here also
it's null and let's
declare our message before
okay so that's the chair error
okay and we put our
uh error link here
that's just the address
okay
so let's also declare a response
the first thing here is to check
if this uh this this function
is running as well okay so if
uh rc
is different than a sqlite okay
[Music]
so that's mean that if there is a
problem
with this function call i go here and
i see where is the problem okay
i just error
uh and i primed the error itself
because we pass this error as
argument here okay
[Music]
so let's let's run
let's run and see what's happened
so there is no problem so if i go here i
find that
here i have eight kilobytes okay
uh so let's just open our database
just to see
if there is something here
here that's our request here
create table i call and say x1 x2 and
the name
okay uh what we're going to do now
uh so we have created
our table okay so now we want to answer
some things in our table okay
uh so by one time
let's uh let's
enter 10 elements in our
in our table okay
i is less than 10
[Music]
i plus plus
uh so let's create string
as query uh
string query
[Music]
equal
what i do
so insert
into our table name is algolinsa okay
i'll go answer
[Music]
values
let's just enter
[Music]
uh
[Music]
for example as x one i
give 12 and as x two egg is 13.
and let's make the name always the jeep
okay
so let's now uh just primes this
uh prime this curie because we're in it
okay
so see out uh
curie
[Music]
uh
and now let's just
[Music]
uh render the key ring so erc
i use lc always this variable here
equal sqlite
[Music]
three execute
and
so i give db my database
and i give this query here
[Music]
no
uh now
i i pass on my error message
as argument here
so this that's an error no switchable
confirmation from
string to char so
for that i just use cstr okay
[Music]
uh
so and let's check also
for the for if there is error messages
so if rc is different than
sql light and skill light
okay
[Music]
i just print the problem itself
the same as this one okay
uh that was insert error
[Music]
okay uh
let's try to run
so there is no problem okay there is no
problem
so here i always enter 12 and 13
okay just here
if i go to my
uh
where is my
excuse me
[Music]
where is my project this one here if i
open
i find that there is other
uh informations added here
okay so that's what i add here
in my project
[Music]
what i want to do now so i i want to
instead of using
the just static number
let's let's make it equal if
okay so let's first add string
[Music]
include
string
[Music]
and here
uh to string
i enter i okay
and here also i enter
for example i plus five okay
i plus five
uh so let's run now
so from zero to now nine and from my
five to fourteen okay uh so let's now
select
okay uh
so notice that every time i ran my
program
just the new informations added to this
database
okay every time i ran my program
so new information is added here
okay
uh every time i ran okay
[Music]
so let's select now so that's for the
insertion
and let's now see how to select
information okay
so the the first thing
i must use is uh sqlite
uh scale light 3 always
i use prepare function
version 2 okay
so you can go online and check
what's this function mean okay
uh
uh so that's my
that's this function so that's here okay
so that's the database the first
argument and then this statement
excuse me and then the maximum length
and the statement and the
so i don't understand this essentially i
don't understand what's that mean also i
just give
null or zero okay uh
so let's enter our information here so
we give our database okay
and then
[Music]
we pass our sql okay
so i want to select
all the information so i select x1
[Music]
x2 and the name
[Music]
from i'll go lancer
[Music]
okay
[Music]
so for the length
for the length i just pass
minus one that's mean don't care okay
and then i pass my the the address of my
statement
this statement here okay so st
and t and the last one is
zero or make it a novel if you want okay
and let's now declare
uh integers a1
and a2 okay
uh let's also
declare
[Music]
my name excuse me
my name just i declare this
just uh for when i i get
that the results i put them here i store
them here okay
[Music]
and now what i do so this
this statement here what this statement
here
so we select from this from this
table here this statement
in this case is associative
array associative table like this one
here
okay which
that's the column of x1
and that's x2
that's x2 and that's the name
okay so it this statement is associative
uh table like this one here okay
so the first thing we have a pointer to
the
to the first call a row here for the
first row okay
so to select this the first row
what i do uh excuse me
so to select the first row what i do uh
so i
just use sqlite
sqlite uh
three
okay uh and this
with this mention will pass this
statement as argument okay
so this function just returns
what this function do is just returns
as first as first place it's it was here
the the pointer is here it returns
this row and the go to the next one
okay that's what this function that's me
that
stnt pointer is here so when i use
a sqlite step it returns this function
return this
this one and go to the next one okay
[Music]
so what i do now
so i use the function
sqlite uh
sqliter3
uh column
cell the first column is an integer okay
the first column is an
integer because x1 is an integer okay
so i up i pass as uh arguments
this statement also and because i want
to
here the first column index is zero and
that's one
and that's two okay so i just want to
get the first one so a1
[Music]
a1 equals
uh the first statement
and i2
[Music]
equal second column which is one okay
uh
so that's a2 here
so let's just print these two
[Music]
informations here excuse me
a1
equal so a1
the value of this a1 here
and a to equal
a2
so let's run now so here
that's the insertion and does the
cell that's the first so
where is 12 and 13 i don't
have any 12 or 13 here
so these values because i say that every
time i ran my program
i i store new informations i remember
that
at the first place i make this equal 12
and this
equal 13 okay uh
so what i can do i just want to
so if you want you can just delete
the database okay if i
delete this database so andren again
so a equal so because i say that
at first place it it returns
the first affirmations the first row
okay
so let's also get then the name this
name okay
[Music]
so my name
[Music]
equal so the name is
in the third column so but here there is
a problem
because this that's an integer this
function
just return integer here i use another
function
which called text okay
[Music]
uh so here also there is a problem i
don't know
i don't know where is the problem here
so let's let's check the type of this
function okay uh
let's go online
and check
uh so that's a blob that's
what is text that's a value yes
so that's in senior const insidio char
okay so let's name it here
[Music]
so and here let's use the name
also
name
[Music]
equal
this my name here
[Music]
let's run
so that's 0
5 and the g so now we say that
this just returned the first but how if
i want to
to select all of the all of my
my rails my returned arrows
here what i do so here i just use
a while loop okay so while loop
so while
uh excuse me
[Music]
uh
i pull i put everything here
if this statement
is not a different is different excuse
me
of sqlite
uh done or just literally
that's it just like this uh
let's first delete because that's too
big now
and we want to just to a sample a simple
example okay so let's see what can
happen here
so answer this this this this this
so there is a problem
uh there is problem here why
why that we have problem here because
when i select
when i select and go to the next one to
the next one to the next one
and go here uh and we have no
information here okay because that
i must say that
excuse me ask year later three
is different than uh
it is different than scale light
uh done
okay so let's run now
before stop
that's it so that's all of my
informations
inside my my database
okay so here here if you want
uh make for example
where x1
is greater than 7
there is no problem
so we select only if this one is greater
than seven
okay normally when we end when we finish
we must
close our database okay sqlite
3 close
our database db
okay
ah
so that's it that's it for this tutorial
i hope that you find this video helpful
for you
and i hope that you like my video and
subscribe to my channel
and thank you for watching
you