Thursday, March 11, 2010

Flash ActionScript3 MySql Querys

One way how to send sql querys in flash is using some kind of server side scripts that receive an URLRequest from flash and send it to sql server.

Here is one way how to do it.

write a php script that takes sql query from request url as a $_GET or $_POST parameter and sends it to sql server. If sql database,username,password are defined in the php file, flash doesnt need to send anything else but a query string e.g "select * from users"

if u want to select database and authenticate yourself within flash, u need to get those variables from GET or POST aswell.

here is my example php script.
-------------------------------
//put php starting tag here,< ? php
//$_GET['default'] we use this parameter to toggle between sql settings defined in php and possible settings sent from actionscript



if( $_GET['default'] == "true")
{
$mysql_host = "mysql12.000webhost.com";
$mysql_database = "a8621303_drupal";
$mysql_user = "a8621303_a862130";
$mysql_password = "852456x";
$con_users = mysql_connect($mysql_host,$mysql_user,$mysql_password);
}
else
{

$mysql_host = $_GET['host'];
$mysql_database = $_GET['database'];
$mysql_user = $_GET['user'];
$mysql_password = $_GET['pass'];
$con_users = mysql_connect($mysql_host,$mysql_user,$mysql_password);
}
mysql_select_db($mysql_database, $con_users);

$query = $_GET['query'];
/* 
NOTE: you shouldnt send queries like this to db without sanitizing/escaping input first 
*/
$result = mysql_query($query);
while($row = mysql_fetch_array( $result ))
{
print_r($row);
}
?>


--------------------------------------
and here is actionscript part that sends the url requests to php script
--------------------------------------
//some global variables
var sqlLoader:URLLoader = new URLLoader();
var sqlRelay :String = "http://sebstorage.comlu.com/FlashToSql.php";//path to php script
var sqlQuery :String = "SELECT * FROM workers";//example query

sqlLoader.addEventListener(Event.COMPLETE,sqlLoaded);//to know when sql data came back
function sqlLoaded(event:Event):void
{
trace(sqlLoader.data);
}
function SendDefaultSqlQuery(query:String):void
{
var urlRequest:URLRequest = new URLRequest(sqlRelay+"? query="+query+"&default=true")
sqlLoader.load(urlRequest);
}
the above function sends GET parameter default, which means that php will use the settings defined in php file.


function SendSqlQuery(query:String,database:String,pass:String,user:String,host:String):void
{
var urlRequest:URLRequest = new URLRequest(sqlRelay+"?host="+host+"&user="+user+"&pass="+pass+"&database="+database+"&query="+query);
sqlLoader.load(urlRequest);
}
this function sends information for sql connection and the query string

Thursday, February 18, 2010

Making Signed Jar

Step 1) Create the key you are going to use for signing the jar archive.

to do this open command prompt and enter a command

keytool -genkey -alias [alias-name] -keystore [keystore-name]

things in green are determined by you. Square Bracket´s "[]" are not necessary.
after the -alias write alias name, the name of your key, can be anything.
after -keystore write full path+ name of your keystore file.
e.g E:\Program Files\keystore-name

if this command is successful, there should be a file with the name u specified in the directory u specified.

after that you use the following command to sign a jar.

jarsigner -keystore [full path to your keystore file] [full path to your jar file] [name of the key(alias)]
note the spaces between commands and also, do not write "[]"´s

Monday, February 8, 2010

SQL Tutvustus

SQL(structured query language) on andmebaaside loomise ja haldamise keel.

Sql andmebaase hallatakse käsurealt ning päringute tulemusena tagastatud info esitatakse teksti kujul.

Andmebaaside lihtsamaks kasutamiseks on hulgaliselt tasulisi ning ka vabavaralisi tarkvara lahendusi nt Heidi SQL või phpMyAdmin.


Andmebaasiga ühenduse loomiseks tuleb sisestada käsk:
mysql -u kasutajanimi -p andmebaasi_nimi


SQL käsud lõppevad semikooloniga ning ükski käst ei ole tõstutundlik.
Käsud võivad paikneda ka mitmel real.

Kõik päringud tagastavad lisaks andmetele ka tagastatud ridade arvu ning päringu täitmisele kulunud aeg.


SQL andmetüübid

Char -erineva pikkusega tekst, kuni 255 tähte
Varchar -tekst
blob -kahendinfo, failid

int -4 baiti
decimal -kümnendarv
float -komaga arvud
date -kuupäeva salvestamiseks YYYY-MM-DD
time -kellaaja salvestamiseks HH:MM:SS
datetime -kell+kuupäev YYYY-MM-DD HH:MM:SS
timestamp -

Uue tabeli loomine:
Create Table tabeli_nimi (veeru_nimi veeru_tüüp)

Andmete Sisestamine:
Insert Into tabeli_nimi [(veergu1,veerg2,...jne)] values (väärtus1,väärtus2,...jne);

Andmete lugemine:
Select veerg1,veerg2,...jne From tabeli_nimi [Where tingimus_on_tõene] [order by veerg1,ASC]

Tabeli uuendamine:
Update tabeli_nimi SET veerg1=väärtus1,veerg2=väärtus2,..jne [Where tingimus_on_tõene]

Andmete kustutamine:
Delete From tabeli_nimi [ Where tingimus_on_tõene];


Tuesday, January 12, 2010

Adding a new disk on OpenBSD

First you need to use fdisk tool.
fdisk wd1
this will add new Master Boot Record data into MRB

then use disklabel to create partitions
disklabel -E wd1
use a to add partitions
use A to create automatic partitions
use p to print partition data.

then create the new filesystem
newfs wd1a

and finally mount the disk somewhere
mount /dev/wd1a /newDisc

optionally to have this disk mounted on each startup add the following line to etc/fstab

/dev/wd1a /newDisc ffs 1 1

wd1a - is our IDE primary master disc
wd = ide