Module sqlite3_lib

Library module for sqlite3.

Copyright © 21 Jun 2008 by Tee Teoh

Version: 1.0.0

Authors: Tee Teoh.

Description

Library module for sqlite3

Data Types

sql_value()

sql_value() = number() | null | iodata()

Values accepted in SQL statements include numbers, atom 'null', and io:iolist().

table_id()

table_id() = atom() | binary() | string()

Function Index

add_columns_sql/2Generates a alter table stmt in SQL.
bin_to_hex/1Converts a plain binary to its hexadecimal encoding, to be passed as a blob literal.
col_type_to_atom/1Maps sqlite3 column type.
create_table_sql/2Generates a table create stmt in SQL.
create_table_sql/3Generates a table create stmt in SQL.
delete_sql/3Using Key as the column name searches for the record with matching Value then deletes that record.
drop_table_sql/1Drop the table Tbl from the database.
read_cols_sql/1 Creates list of columns for select stmt.
read_sql/1Returns all records from table Tbl.
read_sql/2 Returns only specified Columns of all records from table Tbl.
read_sql/3Using Key as the column name searches for the record with matching Value.
read_sql/4 Using Key as the column name searches for the record with matching Value and returns only specified Columns.
sql_to_value/1 Converts an SQL value to an Erlang term.
update_set_sql/1 Creates update set stmt.
update_sql/4 Using Key as the column name and Data as list of column names and values pairs it creates the proper update SQL stmt for the record with matching Value.
value_to_sql/1 Converts an Erlang term to an SQL string.
value_to_sql_unsafe/1 Converts an Erlang term to an SQL string.
write_col_sql/1Creates the column/data stmt for SQL.
write_sql/2Taking Data as list of column names and values pairs it creates the proper insertion SQL stmt.
write_value_sql/1 Creates the values portion of the sql stmt.

Function Details

add_columns_sql/2

add_columns_sql(Tbl::table_id(), Columns::table_info()) -> iolist()

Generates a alter table stmt in SQL.

bin_to_hex/1

bin_to_hex(Binary::binary()) -> binary()

Converts a plain binary to its hexadecimal encoding, to be passed as a blob literal.

col_type_to_atom/1

col_type_to_atom(String::string()) -> atom()

Maps sqlite3 column type.

create_table_sql/2

create_table_sql(Tbl::table_id(), Columns::table_info()) -> iolist()

Generates a table create stmt in SQL.

create_table_sql/3

create_table_sql(Tbl::table_id(), Columns::table_info(), TblConstraints::table_constraints()) -> iolist()

Generates a table create stmt in SQL.

delete_sql/3

delete_sql(Tbl::table_id(), Key::column_id(), Value::sql_value()) -> iolist()

Using Key as the column name searches for the record with matching Value then deletes that record.

drop_table_sql/1

drop_table_sql(Tbl::table_id()) -> iolist()

Drop the table Tbl from the database

read_cols_sql/1

read_cols_sql(Columns::[column_id()]) -> iolist()

Creates list of columns for select stmt.

read_sql/1

read_sql(Tbl::table_id()) -> iolist()

Returns all records from table Tbl.

read_sql/2

read_sql(Tbl::table_id(), Columns::[column_id()]) -> iolist()

Returns only specified Columns of all records from table Tbl.

read_sql/3

read_sql(Tbl::table_id(), Key::column_id(), Value::sql_value()) -> iolist()

Using Key as the column name searches for the record with matching Value.

read_sql/4

read_sql(Tbl::table_id(), Key::column_id(), Value::sql_value(), Columns::[column_id()]) -> iolist()

Using Key as the column name searches for the record with matching Value and returns only specified Columns.

sql_to_value/1

sql_to_value(String) -> any()

Converts an SQL value to an Erlang term.

update_set_sql/1

update_set_sql(Data::[{atom(), sql_value()}]) -> iolist()

Creates update set stmt. Currently supports integer, double/float and strings.

update_sql/4

update_sql(Tbl::table_id(), Key::column_id(), Value::sql_value(), Data::[{column_id(), sql_value()}]) -> iolist()

Using Key as the column name and Data as list of column names and values pairs it creates the proper update SQL stmt for the record with matching Value.

value_to_sql/1

value_to_sql(X::sql_value()) -> iolist()

Converts an Erlang term to an SQL string. Currently supports integers, floats, 'null' atom, and iodata (binaries and iolists) which are treated as SQL strings.

All single quotes (') will be replaced with ''.

value_to_sql_unsafe/1

value_to_sql_unsafe(X::sql_value()) -> iolist()

Converts an Erlang term to an SQL string. Currently supports integers, floats, 'null' atom, and iodata (binaries and iolists) which are treated as SQL strings.

Note that it opens opportunity for injection if an iolist includes single quotes! Replace all single quotes (') with '' manually, or use value_to_sql/1 if you are not sure if your strings contain single quotes (e.g. can be entered by users).

write_col_sql/1

write_col_sql(Cols::[column_id()]) -> iolist()

Creates the column/data stmt for SQL.

write_sql/2

write_sql(Tbl::table_id(), Data::[{column_id(), sql_value()}]) -> iolist()

Taking Data as list of column names and values pairs it creates the proper insertion SQL stmt.

write_value_sql/1

write_value_sql(Values::sql_value()) -> iolist()

Creates the values portion of the sql stmt.


Generated by EDoc, Jan 14 2025, 23:15:13.