vala是專為gnome環境准備的開發語言,之所以vala會出現,是因為目前的glib,gio,gtk+,gnome-lib等等的C語言接口開發 起來實在太繁瑣(這個深有感觸),而同時,如果采用Java,C++這些東西,那又顯得太臃腫。
using Mysql; int main (string[] args) { int rc = 0; ClIEntFlag cflag = 0; string host = "127.0.0.1"; string user = "root"; string password = ""; string database = "test"; int port = 3306; string socket = null; Database mysql = new Mysql.Database (); var isConnected = mysql.real_connect(host, user, passWord, database, port, socket, cflag); if ( ! isConnected ) { rc = 1; stdout.printf("ERROR %u: Connection failed: %s\n", mysql.errno(), MySQL.error()); return rc; } stdout.printf("Connected to MySQL Server version: %s (%lu)\n" , mysql.get_server_info() , (ulong) mysql.get_server_version()); string sql = "SELECT * FROM test LIMIT 10"; rc = mysql.query(sql); if ( rc != 0 ) { stdout.printf("ERROR %u: Query failed: %s\n", mysql.errno(), mysql.error()); return rc; } Result ResultSet = mysql.use_result(); string[] MyRow; while ( (MyRow = ResultSet.fetch_row()) != null ) { stdout.printf("id: %s | data: %s | ts: %s\n", MyRow[0], MyRow[1], MyRow[2]); } // free_result is called automatically // MySQL_close is called automatically return rc; }