sql in livecode Username

Creating desktop or client-server database solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Samuele
Posts: 282
Joined: Mon Oct 11, 2021 7:05 pm
Location: Italy

sql in livecode Username

Post by Samuele » Mon Nov 15, 2021 5:06 pm

hi, how can i check from livecode if in the table UserName (of an Mysql database) there is already a record like that?
thanks!
Samuele.

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: sql in livecode Username

Post by Klaus » Mon Nov 15, 2021 8:32 pm

That is more a SQL question. :D
What is the name of the database field you need to check?

Samuele
Posts: 282
Joined: Mon Oct 11, 2021 7:05 pm
Location: Italy

Re: sql in livecode Username

Post by Samuele » Tue Nov 16, 2021 10:12 am

what do you mean in "database field"?
Samuele.

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: sql in livecode Username

Post by Klaus » Tue Nov 16, 2021 10:35 am

A database table has "fields" to store data in.
Example: A table "UserNames" may have these "fields": name, password, age, address
Capisce? :-)

Samuele
Posts: 282
Joined: Mon Oct 11, 2021 7:05 pm
Location: Italy

Re: sql in livecode Username

Post by Samuele » Tue Nov 16, 2021 6:55 pm

yep, so i need to check the field username of a table Persons
Samuele.

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: sql in livecode Username

Post by Klaus » Tue Nov 16, 2021 7:11 pm

Yep, fetch these data and if they are empty then this name is not yet in the database.

SQL:
select * from UserNames where name = "you name here"

Samuele
Posts: 282
Joined: Mon Oct 11, 2021 7:05 pm
Location: Italy

Re: sql in livecode Username

Post by Samuele » Wed Nov 17, 2021 11:44 am

yes, that's how i do it on SQL, but how do i tell livecode to do that, in other words how can i write a code on livecode that will check, on SQL, or in other words to make livecode speak with SQL :D
thakns!
Samuele.

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: sql in livecode Username

Post by Klaus » Wed Nov 17, 2021 11:59 am

Take a look at this lesson:
https://lessons.livecode.com/m/4071/l/7 ... l-database

To learn more about the basics of LC, please check these stacks:
http://www.hyperactivesw.com/revscriptc ... ences.html

Samuele
Posts: 282
Joined: Mon Oct 11, 2021 7:05 pm
Location: Italy

Re: sql in livecode Username

Post by Samuele » Wed Nov 17, 2021 2:14 pm

thanks
Take a look at this lesson:
https://lessons.livecode.com/m/4071/l/7 ... l-database
this i saw already, that's how i started...
Samuele.

matthiasr
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 190
Joined: Sat Apr 08, 2006 7:55 am
Location: Lübbecke, Germany
Contact:

Re: sql in livecode Username

Post by matthiasr » Wed Nov 17, 2021 2:23 pm

this i saw already, that's how i started...
That lesson contains all needed information to fetch data from a MySQL database.

In short.

1. use revopenDatabase to connect to the DB

2. use revDataFromQuery to fetch the data using your sql statement

3. do whatever you want with the received data

4. use revCloseDatabase to close the database connection again.


Regards,
Matthias

Samuele
Posts: 282
Joined: Mon Oct 11, 2021 7:05 pm
Location: Italy

Re: sql in livecode Username

Post by Samuele » Wed Nov 17, 2021 10:02 pm

thank you Klaus and matthiasr !
Samuele.

Samuele
Posts: 282
Joined: Mon Oct 11, 2021 7:05 pm
Location: Italy

Re: sql in livecode Username

Post by Samuele » Thu Nov 18, 2021 10:32 am

hi, this gives me a syntax error any idea why?
select * from UserNames where name = "you name here"
thanks!
Samuele.

matthiasr
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 190
Joined: Sat Apr 08, 2006 7:55 am
Location: Lübbecke, Germany
Contact:

Re: sql in livecode Username

Post by matthiasr » Thu Nov 18, 2021 10:36 am

Code: Select all

select * from UserNames where name = "you name here"
should be

Code: Select all

select * from UserNames where 'name' = 'you name here'
If i recall correctly then name belongs to the list of MySQL keywords and reserved words.

Btw. if you have phpMyAdmin installed on your webserver you could test your sql statements with that.

phpMyAdmin is a free web app for administration of MySQL Databases. If it is not installed by default on your webserver you can install it.
For me it's a great helper to check/test/debug my sql statements.

Many webservers offer a software installation menu where you can install additional packages. If this is not the case for your web hosting account then you can download phpMyAdmin here
https://www.phpmyadmin.net/downloads/

Post Reply

Return to “Databases”