Warning, /sdk/codevis/thirdparty/soci/docs/interfaces.md is written in an unsupported language. File is not indexed.
0001 # Interfaces 0002 0003 One of the major features of SOCI, although not immediately visible, is the variety of interfaces (APIs) that are available for the user. These can be divided into *sugar*, *core* and *simple*. 0004 0005 ## Sugar 0006 0007 The most exposed and promoted interface supports the syntax sugar that makes SOCI similar in look and feel to embedded SQL. 0008 The example of application code using this interface is: 0009 0010 ```cpp 0011 session sql("postgresql://dbname=mydb"); 0012 0013 int id = 123; 0014 string name; 0015 0016 sql << "select name from persons where id = :id", into(name), use(id); 0017 ``` 0018 0019 ## Core 0020 0021 The above example is equivalent to the following, more explicit sequence of calls: 0022 0023 ```cpp 0024 session sql("postgresql://dbname=mydb"); 0025 0026 int id = 123; 0027 string name; 0028 0029 statement st(sql); 0030 st.exchange(into(name)); 0031 st.exchange(use(id)); 0032 st.alloc(); 0033 st.prepare("select name from persons where id = :id"); 0034 st.define_and_bind(); 0035 st.execute(true); 0036 ``` 0037 0038 The value of the *core* interface is that it is the basis for all other interfaces, and can be also used by developers to easily prepare their own convenience interfaces. 0039 Users who cannot or for some reason do not want to use the natural *sugar* interface should try the *core* one as the foundation and access point to all SOCI functionality. 0040 0041 Note that the *sugar* interface wraps only those parts of the *core* that are related to data binding and query streaming. 0042 0043 ## Simple 0044 0045 The *simple* interface is provided specifically to allow easy integration of the SOCI library with other languages that have the ability to link with binaries using the "C" calling convention. 0046 To facilitate this integration, the *simple* interface does not use any pointers to data except C-style strings and opaque handles, but the consequence of this is that user data is managed by SOCI and not by user code. 0047 To avoid exceptions passing the module boundaries, all errors are reported as state variables of relevant objects. 0048 0049 The above examples can be rewritten as (without error-handling): 0050 0051 ```cpp 0052 #include <soci-simple.h> 0053 0054 // ... 0055 session_handle sql = soci_create_session("postgresql://dbname=mydb"); 0056 0057 statement_handle st = soci_create_statement(sql); 0058 0059 soci_use_int(st, "id"); 0060 soci_set_use_int(st, "id", 123); 0061 0062 int namePosition = soci_into_string(st); 0063 0064 soci_prepare(st, "select name from persons where id = :id"); 0065 0066 soci_execute(st, true); 0067 0068 char const * name = soci_get_into_string(st, namePosition); 0069 0070 printf("name is %s\n", name); 0071 0072 soci_destroy_statement(st); 0073 soci_destroy_session(sql); 0074 ``` 0075 0076 The *simple* interface supports single and bulk data exchange for static binding. 0077 Dynamic row description is not supported in this release. 0078 0079 See [Simple client interface](api/client.md#simple-client-interface) reference documentation for more details. 0080 0081 ## Low-level backend interface 0082 0083 The low-level backend interface allows to interact with backends directly and in principle allows to access the database without involving any other component. 0084 There is no particular reason to use this interface in the user code.