overview.edoc 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. MySQL/OTP – MySQL client library for Erlang/OTP
  2. Copyright (C) 2014 Viktor Söderqvist
  3. This file is part of MySQL/OTP.
  4. MySQL/OTP is free software: you can redistribute it and/or modify it under
  5. the terms of the GNU Lesser General Public License as published by the Free
  6. Software Foundation, either version 3 of the License, or (at your option)
  7. any later version.
  8. This program is distributed in the hope that it will be useful, but WITHOUT
  9. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. more details.
  12. You should have received a copy of the GNU Lesser General Public License
  13. along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. ------------------------------------------------------------------------
  15. @title MySQL/OTP User's Guide
  16. @doc
  17. MySQL/OTP is a driver for connecting Erlang/OTP applications to MySQL
  18. databases. It is a native implementation of the MySQL protocol in Erlang.
  19. This is the documentation generated from the Erlang source code using EDoc.
  20. The project page is on Github:
  21. <a href="https://github.com/mysql-otp/mysql-otp/"
  22. target="_top">https://github.com/mysql-otp/mysql-otp/</a>.
  23. For the reference manual see the <a href="mysql.html">mysql</a> module.
  24. <h2 id="value-representation">Value representation</h2>
  25. <table>
  26. <thead>
  27. <tr>
  28. <th>MySQL</th>
  29. <th>Erlang</th>
  30. <th>Example</th>
  31. </tr>
  32. </thead>
  33. <tbody>
  34. <tr>
  35. <td>INT, TINYINT, etc.</td>
  36. <td>`integer()'</td>
  37. <td>`42'</td>
  38. </tr>
  39. <tr>
  40. <td>VARCHAR, TEXT, etc.</td>
  41. <td>`unicode:chardata()' [<a href="#vn1">1</a>]</td>
  42. <td>`<<"foo">>', `"bar"'</td>
  43. </tr>
  44. <tr>
  45. <td>VARBINARY, BLOB, etc.</td>
  46. <td>`binary()'</td>
  47. <td>`<<1, 2, 3, 4>>'</td>
  48. </tr>
  49. <tr>
  50. <td>BIT(N)</td>
  51. <td>`<<_:N/bitstring>>'</td>
  52. <td>`<<255, 6:3>>'</td>
  53. </tr>
  54. <tr>
  55. <td>FLOAT, DOUBLE</td>
  56. <td>`float()'</td>
  57. <td>`3.14'</td>
  58. </tr>
  59. <tr>
  60. <td>DECIMAL(P, S)</td>
  61. <td>`integer()' when S == 0<br />
  62. `float()' when P =&lt; 15 and S &gt; 0<br />
  63. `binary()' when P &gt;= 16 and S &gt; 0 [<a href="#vn2">2</a>]</td>
  64. <td>`42'<br />`3.14'<br />`<<"3.14159265358979323846">>'</td>
  65. </tr>
  66. <tr>
  67. <td>DATETIME, TIMESTAMP</td>
  68. <td>`calendar:datetime()' [<a href="#vn3">3</a>]</td>
  69. <td>`{{2014, 11, 18}, {10, 22, 36}}'</td>
  70. </tr>
  71. <tr>
  72. <td>DATE</td>
  73. <td>`calendar:date()'</td>
  74. <td>`{2014, 11, 18}'</td>
  75. </tr>
  76. <tr>
  77. <td>TIME</td>
  78. <td>`{Days, calendar:time()}' [<a href="#vn3">3</a>,
  79. <a href="#vn4">4</a>]</td>
  80. <td>`{0, {10, 22, 36}}'</td>
  81. </tr>
  82. <tr>
  83. <td>NULL</td>
  84. <td>`null'</td>
  85. <td>`null'</td>
  86. </tr>
  87. </tbody>
  88. </table>
  89. Notes:
  90. <ol>
  91. <li id="vn1">When fetching VARCHAR, TEXT etc. they are returned as `binary()'.
  92. When sending (insert or update) any `unicode:chardata()' is accepted as
  93. input. In a (possibly deep) list of integers and binaries, the integers are
  94. treated as Unicode codepoints while binaries are treated as UTF-8 encoded
  95. Unicode data. For lists, an error occurs if you try to send invalid Unicode
  96. data, but if the input is a pure binary, no validation will be done. This is
  97. to allow sending binary non-Unicode data for MySQL's binary strings (BLOB,
  98. VARBINARY, etc.).</li>
  99. <li id="vn2">DECIMALs are returned as `integer()' or `float()' when the value
  100. can be represented without precision loss and as `binary()' for high
  101. precision DECIMAL values. This is similar to how the `odbc' OTP application
  102. treats DECIMALs.</li>
  103. <li id="vn3">For `DATETIME', `TIMESTAMP' and `TIME' values with franctions of
  104. seconds, we use a float for the seconds part. (These are unusual and were
  105. added to MySQL in version 5.6.4.)</li>
  106. <li id="vn4">Since `TIME' can be outside the `calendar:time()' interval, we use
  107. the format as returned by `calendar:seconds_to_daystime/1' for `TIME'
  108. values.</li>
  109. </ol>
  110. <h2>Copying</h2>
  111. Copyright 2014 The authors of MySQL/OTP. See the project page at
  112. <a href="https://github.com/mysql-otp/mysql-otp"
  113. target="_top">https://github.com/mysql-otp/mysql-otp</a>.
  114. This library is free software licensed under the GNU LGPL which allows you to
  115. use it in proprietary applications as well as free software applications with
  116. other licenses. This documentation is generated from the source code and thus
  117. goes under the same license as the library itself.