generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: A useful little script ( sql.lua )

Previous Thread :: Next Thread 
SDuke524 is not online. SDuke524
Joined: 29 Jul 2008
Total Posts: 6267
19 Dec 2011 03:04 PM
Link : http://www.roblox.com/--item?id=67508462

It currently has `USE`,`INSERT`, `SHOW`, `SELECT`, `CREATE`, `DELETE` and `UPDATE`. It also includes `_G.print_r()` and `_G.explode()`.

How to use :

## _G.print_r() ##

`_G.print_r()` will take an array and print it out in the output. Works just like print_r() in PHP.

    local a={1,"r",{1,2,3}};
    
    _G.print_r(a);
Output :
> [1] => 1
[2] => r
[3] => array
(
 [1] => 1
 [2] => 2
 [3] => 3
)

## _G.explode() ##
`_G.explode()` will take a string and a pattern. Returns an array and will work just like explode() in PHP.

    local str="hi,ter,qwerty,boi";
    
    _G.print_r(_G.explode(str,','));
Output :
> [1] => hi
[2] => ter
[3] => qwerty
[4] => boi

## _G.sql_query() ##
_G.sql_query() will take a string. Depending on the query, it will return either an array or void.

    _G.sql_query("query here :P");

## USE ##
`USE` selects the database that will be used.

    _G.sql_query("USE ​database_name");

## CREATE ##
`CREATE` is used to make new tables and databases

To make a new database you would do :

    _G.sql_query("CREATE database database_name");

and this will create a new database named "database_name"

To make a new table you would do :

    _G.sql_query("USE database_name");
    _G.sql_query("CREATE table table_name (id NUMBER,name STRING,strange BOOLEAN)");

and this will create a table named table_name with the collumns id, name and strange.

## INSERT ##
`INSERT INTO` will insert a new row into your table. You must identify the table, the collumns you're entering into, and the values being entered.

    _G.sql_query("USE database_name");
    _G.sql_query("INSERT INTO table_name (id,name,strange) VALUES(1,'SD',true)");
**NOTE** The values must line up with what you put in the first brackets, and it will error if you put in the wrong data type.

## UPDATE ##
`UPDATE` will update a row in your database. You will use the keyword `WHERE` to identify which ones you want to edit. If you don't include `WHERE`, it'll update every row in the table.

    _G.sql_query("USE database_name");
    _G.sql_query("UPDATE table_name SET strange=false WHERE id=1");

or

    _G.sql_query("UPDATE database_name.table_name SET strange=false WHERE id=1");

*( Thanks to popinman322 for helping me debug the conditionals )*
You can only use one conditional as of right now. The comparison symbols that can be used are =,!=,>,<,<=,>= which should be self-explanatory to those of you reading this.

## DELETE ##
`DELETE` will delete a row. You must use the keyword `WHERE` to identify which ones will be deleted. If you don't include `WHERE`, it'll delete every row in the table.

    _G.sql_query("USE database_name");
    _G.sql_query("DELETE FROM table_name WHERE id=1");
or
    _G.sql_query("DELETE FROM database_name.table_name WHERE id=1");

## SELECT ##
This will return an array of the information in which you requested. First you will put `SELECT` and in between that and `FROM` will be the collumns you want it to return. If you want it to return all the collumns, just put a "*", if you want to return just a couple columns, seperate them by commas. Then after `FROM` comes the table name. Then the `WHERE` and conditional. Without `WHERE` it will return everything in the table.

    local arg=_G.sql_query("SELECT * FROM table_name");
    _G.print_r(arg);
Output :
> [1] => array
(
[id] => 1
[name] => SD
[strange] => false
)

or

    local arg=_G.sql_query("SELECT id,strange FROM database_name.table_name WHERE name='SD'");
    _G.print_r(arg);
Output :
> [1] => array
(
[id] => 1
[strange] => false
)

## SHOW ##
Mostly for debugging, SHOW will print out information you ask for in the output.

    _G.sql_query("SHOW databases");

will print out the names of all the databases in the output like so :

> db1
db2
db3

    _G.sql_query("SHOW tables FROM database_name");

will print out the names of all the tables in "database_name" like so :

> table1
table2
table3

    _G.sql_query("SHOW columns FROM database_name.table_name");

will show all the columns in table_name like so :

[1] => array
(
[id] => 1
[name] => SD
[strange] => false
)


Comments? Suggestions? Ideas? Don't comment on my grammar or anything, I'm tired.
Report Abuse
skipperguy12 is not online. skipperguy12
Joined: 09 Oct 2009
Total Posts: 955
19 Dec 2011 03:06 PM
I'm no extreeme advanced scripter, but WOW!
Report Abuse
SDuke524 is not online. SDuke524
Joined: 29 Jul 2008
Total Posts: 6267
19 Dec 2011 03:51 PM
Thank you?
Report Abuse
SDuke524 is not online. SDuke524
Joined: 29 Jul 2008
Total Posts: 6267
19 Dec 2011 04:08 PM
So nobody here actually knows what SQL is...
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
19 Dec 2011 04:30 PM
I've never cared to learn it. ^_^
Report Abuse
SDuke524 is not online. SDuke524
Joined: 29 Jul 2008
Total Posts: 6267
19 Dec 2011 04:34 PM
Honest ^_^

Well do you at least know what it is? Because that should give a good enough explanation for you to understand how it's used.
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
19 Dec 2011 05:55 PM
Something to do with server-sided scripting/programming.
Plus databases.

I know only very little about databases, and that's with Visual Basic...

I didn't look at the content of the functions, but I looked over the results. And skimmed through the other keywords USE/CREATE/etc.
Report Abuse
SDuke524 is not online. SDuke524
Joined: 29 Jul 2008
Total Posts: 6267
19 Dec 2011 11:00 PM
Well to give you a bit of an idea of what it's used for, I'm making a football game using it, this game will work similar to the superstar mode of madden, so it'll save multiple values for different skills and stats for each player. Then they can easily be listed in any spot I need it to be listed at. So I could have a hall of fame for each position, if I wanted to have coaches and trade stuff, I could allow for people to search for players by stats, I could allow for people to compare themselves to specific users easier, and much, much more.

Not to mention I'm planning to soon allow for functions to be a data-type. Most likely I'll have to have a seperate insert function for it however, if you know of a way to insert it similar to the way other variables are being inserted, it would be really apreciated.
Report Abuse
SDuke524 is not online. SDuke524
Joined: 29 Jul 2008
Total Posts: 6267
20 Dec 2011 08:26 AM
bump
Report Abuse
SDuke524 is not online. SDuke524
Joined: 29 Jul 2008
Total Posts: 6267
20 Dec 2011 06:07 PM
Am I the only one that finds this useful?
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
20 Dec 2011 06:08 PM
As of right now, yes, it seems so.
I still haven't looked at it yet.
I have finals I need to "study" for.
Report Abuse
pugzy is not online. pugzy
Joined: 16 Aug 2007
Total Posts: 11957
20 Dec 2011 06:13 PM
I know what SQL is. I am making a browser based game with it and PHP. I thought SQL, was quite easy to learn...
Report Abuse
Spectrumw is not online. Spectrumw
Joined: 04 Aug 2009
Total Posts: 13510
20 Dec 2011 06:19 PM
Ohai SDuke.
Report Abuse
SDuke524 is not online. SDuke524
Joined: 29 Jul 2008
Total Posts: 6267
21 Dec 2011 01:10 PM
@pugzy
Why would you use php for it? The only time I ever use PHP is for clients websites. ASP.NET+JavaScript+HTML 5 is what you should be using since you can actually make animations with that. Check out these sites to see what I mean :

http://spritely.net

http://www.chromeexperiments.com/webgl
Report Abuse
digpoe is not online. digpoe
Joined: 02 Nov 2008
Total Posts: 9092
21 Dec 2011 01:13 PM
I know what SQL is, because I use MySQL to make sites, with my dad. :P
Report Abuse
SDuke524 is not online. SDuke524
Joined: 29 Jul 2008
Total Posts: 6267
21 Dec 2011 03:48 PM
Nice to know someone apreciates it.
Report Abuse
pugzy is not online. pugzy
Joined: 16 Aug 2007
Total Posts: 11957
22 Dec 2011 01:27 AM
"Why would you use php for it? The only time I ever use PHP is for clients websites. "

Because I learned PHP before ASP.net? I don't know? PHP isn't a bad language.
Report Abuse
SDuke524 is not online. SDuke524
Joined: 29 Jul 2008
Total Posts: 6267
22 Dec 2011 10:24 AM
It isn't at all however, it isn't useful for what you said you're using it for at all.
Report Abuse
Miro034 is not online. Miro034
Joined: 07 Oct 2009
Total Posts: 6568
22 Dec 2011 10:54 AM
What does this script do?
Report Abuse
SDuke524 is not online. SDuke524
Joined: 29 Jul 2008
Total Posts: 6267
22 Dec 2011 11:14 AM
@Miro

read the top post...
Report Abuse
Miro034 is not online. Miro034
Joined: 07 Oct 2009
Total Posts: 6568
22 Dec 2011 11:18 AM
What's so special about this? It just prints. By the way, I think ure one of the best scripters of ROBLOX.
Report Abuse
SDuke524 is not online. SDuke524
Joined: 29 Jul 2008
Total Posts: 6267
22 Dec 2011 01:41 PM
Basically it's a different language for database management.
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
22 Dec 2011 01:48 PM
Do you think, by any chance, you could use this for simplified DP?
I mean, if we use DP as our 'database' then we could save everything in string form, which uses MUCH less space than instance data.
Report Abuse
Seranok is online. Seranok
Joined: 12 Dec 2009
Total Posts: 11083
22 Dec 2011 02:23 PM
I have a serialization scripts that saves nearly all types of userdata, tables, strings, numbers, etc, so you can just do something like:

local Database = {}
Database[Player.Name] = {Points = 5, Position = Player.Character.GetModelCFrame().p}

local str = serialize(Database[Player.Name])
-- now you use data persistence to save the string
-- and loadstring it back later
Report Abuse
SDuke524 is not online. SDuke524
Joined: 29 Jul 2008
Total Posts: 6267
22 Dec 2011 02:39 PM
@agent
Easily. Just save a query and then load it up afterwards.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image