overview.edoc 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. MySQL/OTP – MySQL client library for Erlang/OTP
  2. Copyright (C) 2014-2019 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>]<br />
  64. `{decimal, Value}' [<a href="#vn3">3</a>] (parameter only)</td>
  65. <td>`42'<br />`3.14'<br />`<<"3.14159265358979323846">>'<br />
  66. `{decimal, 10.2}'</td>
  67. </tr>
  68. <tr>
  69. <td>DATETIME, TIMESTAMP</td>
  70. <td>`calendar:datetime()' [<a href="#vn4">4</a>]</td>
  71. <td>`{{2014, 11, 18}, {10, 22, 36}}'</td>
  72. </tr>
  73. <tr>
  74. <td>DATE</td>
  75. <td>`calendar:date()'</td>
  76. <td>`{2014, 11, 18}'</td>
  77. </tr>
  78. <tr>
  79. <td>TIME</td>
  80. <td>`{Days, calendar:time()}' [<a href="#vn4">4</a>,
  81. <a href="#vn5">5</a>]</td>
  82. <td>`{0, {10, 22, 36}}'</td>
  83. </tr>
  84. <tr>
  85. <td>NULL</td>
  86. <td>`null'</td>
  87. <td>`null'</td>
  88. </tr>
  89. </tbody>
  90. </table>
  91. Notes:
  92. <ol>
  93. <li id="vn1">When fetching VARCHAR, TEXT etc. they are returned as `binary()'.
  94. When sending (insert or update) any `unicode:chardata()' is accepted as
  95. input. In a (possibly deep) list of integers and binaries, the integers are
  96. treated as Unicode codepoints while binaries are treated as UTF-8 encoded
  97. Unicode data. For lists, an error occurs if you try to send invalid Unicode
  98. data, but if the input is a pure binary, no validation will be done. This is
  99. to allow sending binary non-Unicode data for MySQL's binary strings (BLOB,
  100. VARBINARY, etc.).</li>
  101. <li id="vn2">DECIMALs are returned as `integer()' or `float()' when the value
  102. can be represented without precision loss and as `binary()' for high
  103. precision DECIMAL values. This is similar to how the `odbc' OTP application
  104. treats DECIMALs.</li>
  105. <li id="vn3">DECIMALs can be sent as `{decimal, Value}' (where Value is a
  106. number, string or binary) but values received from the database are
  107. never returned in this format.</li>
  108. <li id="vn4">For `DATETIME', `TIMESTAMP' and `TIME' values with fractions of
  109. seconds, we use a float for the seconds part. (These are unusual and were
  110. added to MySQL in version 5.6.4.)</li>
  111. <li id="vn5">Since `TIME' can be outside the `calendar:time()' interval, we use
  112. the format as returned by `calendar:seconds_to_daystime/1' for `TIME'
  113. values.</li>
  114. </ol>
  115. <h2>Copying</h2>
  116. Copyright 2014-2021 The authors of MySQL/OTP. See the project page at
  117. <a href="https://github.com/mysql-otp/mysql-otp"
  118. target="_top">https://github.com/mysql-otp/mysql-otp</a>.
  119. This library is free software licensed under the GNU LGPL which allows you to
  120. use it in proprietary applications as well as free software applications with
  121. other licenses. This documentation is generated from the source code and thus
  122. goes under the same license as the library itself.