Created
July 12, 2013 05:32
-
-
Save anatooly/5982096 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// alac mysql.vala --pkg mysql --Xcc=-lmysqlclient | |
using Mysql; | |
int main (string[] args) | |
{ | |
int rc = 0; | |
string host = "127.0.0.1"; | |
string user = "root"; | |
string password = ""; | |
string database = "test"; | |
int port = 3306; | |
string socket = null; | |
ClientFlag cflag = 0; | |
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 999990, 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[] row; | |
while ( (row = ResultSet.fetch_row()) != null ) { | |
stdout.printf("Key: %s, value: %s\n", row[0], row[1]); | |
} | |
// free_result is called automatically | |
// mysql_close is called automatically | |
return rc; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment