SDuke524Join Date: 2008-07-29 Post Count: 6267 |
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.
|
|
|
A suggestion would be to add in manual global fixing so you don't have to have _G[function].
for index, value in next, _G do
getfenv()[index] = value
end
And I just have a question... What would I use this for? Just wanted to know. |
|
SDuke524Join Date: 2008-07-29 Post Count: 6267 |
@TheNew
If you wanna hack it like that, be my guest.
Also it's used for anything SQL is used for. Database saving. You could use it to keep your leaderstats protected, you could use it to hold information for players that have left the game already, basically anything that requires data to be saved.
If you used SQL or MySQL you would truly understand it a lot better. |
|
|
Also, is a Database just like a Library that ROBLOX has? Or... something else... If it is something else, please explain. |
|
|
Oh, I haven't used either of those... Sadly, I am only a RBX.lua and a [learning] Java programmer... |
|
ProfileJoin Date: 2008-12-27 Post Count: 125 |
TheNewScripter, java is a waste of time, i hardly call anyone who uses it a 'programmer' learn C/C++ your better off there if you want to make GUI applications with it use QT framework. |
|
|
Back on topic though... When I say a library that ROBLOX has, I meant a Pseudo-Library. Anyway, is it just a table? |
|
myrkosJoin Date: 2010-09-06 Post Count: 8072 |
C/C++ isn't a language, Profile. |
|
SDuke524Join Date: 2008-07-29 Post Count: 6267 |
Ok... for the sake of keeping conversation going, people list ideas of things you could use this for. |
|
OysiJoin Date: 2009-07-06 Post Count: 9058 |
[ Content Deleted ] |
|
SDuke524Join Date: 2008-07-29 Post Count: 6267 |
Yeah, however when SORT BY is done, this will be a lot better. |
|
GigsD4XJoin Date: 2008-06-06 Post Count: 3794 |
This is actually pretty cool, have you guys tested its efficiency? CALL IN THE JULIEN/OYSIs |
|
GigsD4XJoin Date: 2008-06-06 Post Count: 3794 |
Oh and you should add the AND, OR, XOR, and LIMIT statements. |
|
TheMyrcoJoin Date: 2011-08-13 Post Count: 15105 |
>JULIEN/OYSIs
MEH!?
~Myrco; Music lover, nederlands/dutch and a scripter |
|
|
What sorting algorithm are you going to use?
|
|
SDuke524Join Date: 2008-07-29 Post Count: 6267 |
@ninja
Whatever I make up when I get there. |
|
|
Legend26Join Date: 2008-09-08 Post Count: 10586 |
Did you even read the thread? The link is right at the top of the first post... |
|
exspammerJoin Date: 2011-06-13 Post Count: 12 |
Do you know what is even more useful... LISP |
|
SDuke524Join Date: 2008-07-29 Post Count: 6267 |
So has any of the 5 people who have taken this done anything with this? If so I'd like to see it.
|
|
Legend26Join Date: 2008-09-08 Post Count: 10586 |
I haven't really done anything.
Personally, I can't fathom how all these web languages work in the first place and don't really like how SQL seems to work. |
|
NVIJoin Date: 2009-01-11 Post Count: 4744 |
I'm late, but Profile is an idiot.
Java is a widely used language. It's what Android runs off of, what enterprise-level servers typically use, and so much more. It could even feasibly overtake C/C++ in the next few years.
Oh, and by the way, Qt is absolutely useless.
Please stop spreading your crap, Profile. |
|
myrkosJoin Date: 2010-09-06 Post Count: 8072 |
"Java is a widely used language. It's what Android runs off of, what enterprise-level servers typically use, and so much more. It could even feasibly overtake C/C++ in the next few years."
No. It can't. They are totally different realms that barely overlap.
"Oh, and by the way, Qt is absolutely useless."
More like you've never had a look at it and thus your ignorance tells you that it's useless. |
|
GigsD4XJoin Date: 2008-06-06 Post Count: 3794 |
I was editing the script and I was confused when you wrote "collumns" instead of "columns" instead of "rows" XD |
|
LocalChumJoin Date: 2011-03-04 Post Count: 6906 |
Java sucks. Live with it. |
|