Novy programovaci jazyk a platforma Googlu Dart

S Dartem jsem se pokousel spratelit uz nekolikrat. Bohuzel jako pouha nahrada JS mi prisel trochu nepotrebny ale ted, jak se v Dartu mohou psat i Chrome Packaged Apps a Konzolove aplikace, jejichz vystup se vypisuje v Dart Editoru(nebo urcite nekde v chromu, pokud Dart editor neni spusteny) jsem se rozhodl se ho naucit. My si dnes neukazeme zadny Hello World program, ale neco trochu slozitejsiho a totiz praci s MySQL databazi. Jsem ted na Linuxu, na Elementary OS Luna, takze screenshoty budou z neho. Nicmene co se tyka samotneho Dartu, to by melo byt stejne na vsech platformach a OS. Prvni co musime udelat je nainstalovat MySQL, pokud jej jeste nemate. Ja jsem to udelal nejjednodussi cestou a to v Software Centru:



Dale si MySQL nastavime skriptem, proto spustte v terminalu tento prikaz:

sudo /usr/bin/mysql_secure_installation :
sunamo@m:~$ sudo /usr/bin/mysql_secure_installation
[sudo] password for sunamo:
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y
... Success!
By default, MySQL comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] n
... skipping.
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
Pak se do MySQL prihlaste:
sunamo@m:~$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 57
Server version: 5.5.34-0ubuntu0.12.04.1 (Ubuntu)
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
A pote zjistete jake mate databaze:
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)

Zmente databazi na temp, protoze s touto budeme pracovat:
mysql> use test;

Database changed

Protoze ted nejspis databaze test zadne tabulky mit nebude...

mysql> show tables -> ;
Empty set (0.00 sec)

..jednu ukazkovou tabulku si vytvorime...

mysql> CREATE TABLE Users(ID VARCHAR(32), Name VARCHAR(32), Surname VARCHAR(32), DateBorn DATE);

Query OK, 0 rows affected (0.18 sec)

…vlozime do ni data – 2 radky, abychom videli ze radku lze vzit neomezene….

mysql> INSERT INTO Users VALUES (1, "Radek", "Jancik", -> "1993-4-2");

Query OK, 1 row affected, 1 warning (0.18 sec)

mysql> INSERT INTO Users VALUES(2, "Nikol", "Jancikova", "1989-06-21");
Query OK, 1 row affected (0.08 sec)

…a na tyto data se podivame, jak se ulozili. Protoze jsem zacatecnik v MySQL, nevim jeste jak nastavit ceske collation a proto tam je Jan?ik.


mysql> SELECT * FROM Users;
+------+-------+-----------+------------+
| ID | Name | Surname | DateBorn |
+------+-------+-----------+------------+
| 1 | Radek | Jan?ik | 1993-04-02 |
| 2 | Nikol | Jancikova | 1989-06-21 |
+------+-------+-----------+------------+
2 rows in set (0.00 sec)

Nyni se presuneme do Dartu. Vytvorte si novy projekt Console Application(ja jsem si ho pojmenoval DartLearn). Otevrete soubor pubspec.yaml a v zavislostech/Dependecies specifikujte balicek sqljocky a ulozte(ctrl+s). Znovu se vam sestavi workspace, coz muze chvilku trvat.

Pote do vytvoreneho dart souboru nahradte timto obsahem(pokud jste odskrtli vytvorit sablonovy obsah, musite tento soubor samozrejme vytvorit(ctrl+n)): https://gist.github.com/sunamo/7582007 . Posledni vec co musite nastavit je launcher, abyste tento program mohli spustit. Proto stisknete ctrl+shift+m a nastavte launcher pro vasi konzolovou aplikaci a vas skript:



Puvodne jsem chtel udelat tuto aplikaci jako webovou, ale pri pouhem nastaveni launcheru mi Dartium vyhazovalo chybu “The built-in library dart:io is not available on Dartium.” a apache se mi na linuxu pres spravce softwaru nepodarilo nainstalovat(nezkousel jsem synaptic). dart:io je totiz serverova knihovna urcena pouze pro server. Spustte (ctrl+r) a meli byste mit v konzoli data z vasi MySQL DB:



 

Preji vam hodne stesti s Dartem.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.