diff --git a/Makefile b/Makefile index 05c574c0..e9c78eb5 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ LIBDIR=$(shell erl -eval 'io:format("~s~n", [code:lib_dir()])' -s init stop -noshell) -VERSION=0.4.0 +VERSION=0.4.1 PKGNAME=emysql APP_NAME=emysql diff --git a/README.md b/README.md index 9c3aefeb..c6d8687e 100644 --- a/README.md +++ b/README.md @@ -242,6 +242,7 @@ Sample programs are in ./samples. * [d\_prepared\_statement](http://github.com/Eonblast/Emysql/blob/master/samples/d_prepared_statement.erl) - Using prepared statements * [e\_stored\_procedure](http://github.com/Eonblast/Emysql/blob/master/samples/e_stored_procedure.erl) - Using stored procedures * [f\_load\_from\_file](http://github.com/Eonblast/Emysql/blob/master/samples/f_load_from_file.erl) - Fast loading of data from a flat file +* [g\_rows\_as\_json](http://github.com/Eonblast/Emysql/blob/master/samples/g_rows_as_json.erl) - Conversion of database rows into JSON To run the samples, create the database as listed above at localhost, and simply run the compile & run batches: @@ -274,23 +275,18 @@ The Emysql driver is an Erlang gen-server, and, application. #### Adding a Pool - % emysql:add_pool(PoolName, PoolSize, Username, Password, Host, Port, Database, Encoding) -> - % ok | {error, pool_already_exists} - % PoolName = atom() - % PoolSize = integer() - % Username = string() - % Password = string() - % Host = string() - % Port = integer() - % Database = string() - % Encoding = undefined | atom() - - emysql:add_pool(mypoolname, 1, "username", "mypassword", "localhost", 3306, "mydatabase", utf8). - - If ``Encoding`` is ``undefined``, then no encoding is set. +To add a pool, you need to use one of the `emysql:add_pool/K` variants. I recommend using +`emysql:add_pool/2` which takes a proplist of parameters and is a bit easier to work with +rather than getting a parameter list correct. See the documentation for what options the +add_pool call accepts. #### More Record Types +Emysql usually operates with a number of different record types from the database. The driver +returns "raw" responses as "packets" and leaves it up to the calling application to handle +the result, usually by using one of the conversion routines in `emysql` to turn the data into +a more suitable format. + -record(result_packet, {seq_num, field_list, rows, extra}). -record(ok_packet, {seq_num, affected_rows, insert_id, status, warning_count, msg}). @@ -350,7 +346,7 @@ For other record types, see include/emysql.hrl. #### Converting Row Data To Records - % emysql_util:as_record(ResultPacket, RecordName, Fields) -> Result + % emysql:as_record(ResultPacket, RecordName, Fields) -> Result % ResultPacket = result_packet() % RecordName = atom() (the name of the record to generate) % Fields = [atom()] (the field names to generate for each record) @@ -361,20 +357,20 @@ For other record types, see include/emysql.hrl. fetch_foo() -> Result = emysql:execute(pool1, <<"select bar, baz, bat from foo">>), - Recs = emysql_util:as_record(Result, foo, record_info(fields, foo)), + Recs = emysql:as_record(Result, foo, record_info(fields, foo)), [begin io:format("foo: ~p, ~p, ~p~n", [Foo#foo.bar, Foo#foo.baz, Foo#foo.bat]) end || Foo <- Recs]. #### Converting Row Data To JSON - % emysql_util:as_json(ResultPacket) -> Result + % emysql:as_json(ResultPacket) -> Result % Result = [json()] Result = emysql:execute(pool1, <<"select bar, baz from foo">>), - JSON = emysql_util:as_json(Result). - #[[{<<"bar">>,<<"bar_value">>}, {<<"baz">>,<<"baz_value">>}], ...] + JSON = emysql:as_json(Result). + % [[{<<"bar">>,<<"bar_value">>}, {<<"baz">>,<<"baz_value">>}], ...] Note that you are getting back a list of erlang terms in accordance with EEP-18. For actual utf8 binary JSON string you will need external library like [jsx](https://github.com/talentdeficit/jsx) or [jiffy](https://github.com/davisp/jiffy) @@ -422,144 +418,9 @@ Some tests can take up to half a minute to finish on a slow machine. These tests currently check access to the database (environment suite) the same functionality as the samples (basics suite) and for race conditions as described in issue #9. Thank you, Ransom! -### Encoding Tests - -Currently the main focus is on Unicode test cases and encoding conversions, -in the suites utf8_SUITE, latin_SUITE, utf8_to_latindb_SUITE, -latin_to_utf8db_SUITE. Especially the silent conversions of list strings -to the appropriate binary format were a bit of a challenge. - -For the encoding tests, please create these databases: - - create database hello_utf8_database character set utf8; - use hello_utf8_database; - create table hello_table (hello_text char(20)); - grant all privileges on hello_utf8_database.* to hello_username@localhost identified by 'hello_password'; - - create database hello_latin1_database character set latin1; - use hello_latin1_database; - create table hello_table (hello_text char(20)); - grant all privileges on hello_latin1_database.* to hello_username@localhost identified by 'hello_password'; - -To run the encoding tests do: - - make encoding-test - -To run all tests (this includes issue tests, see below): - - make all-test - - -You see the test results when opening test/index.html with a browser. It should look like this: - -
Test Name | -Label | -Test Run Started | -_Ok_ | -Failed | -Skipped (User/Auto) |
-
-Missing Suites |
-Node | -
---|---|---|---|---|---|---|---|
me.Emysql. basics_SUITE | -- | -Tue Dec 13 2011 04:17:29 | - -7 | -0 | -0 (0/0) | -0 | -ct@machine | - -
me.Emysql. environment_SUITE | - -- | -Tue Dec 13 2011 04:17:29 | -6 | -0 | -0 (0/0) | -0 | -ct@machine | - -
Total | - | - | 13 | -0 | -0 (0/0) | -0 | -- |