{"id":18847807,"url":"https://github.com/interkosmos/fortran-sqlite3","last_synced_at":"2025-04-14T08:10:14.158Z","repository":{"id":46290469,"uuid":"388601962","full_name":"interkosmos/fortran-sqlite3","owner":"interkosmos","description":"Fortran 2018 interface bindings to SQLite 3","archived":false,"fork":false,"pushed_at":"2024-04-11T22:17:22.000Z","size":70,"stargazers_count":30,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-14T08:09:49.886Z","etag":null,"topics":["fortran","fortran-package-manager","fpm","sqlite","sqlite3"],"latest_commit_sha":null,"homepage":"","language":"Fortran","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/interkosmos.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2021-07-22T21:29:43.000Z","updated_at":"2025-03-27T12:59:45.000Z","dependencies_parsed_at":"2023-09-24T11:59:04.311Z","dependency_job_id":"de790c16-4f9b-48ec-849f-15d22feda283","html_url":"https://github.com/interkosmos/fortran-sqlite3","commit_stats":{"total_commits":42,"total_committers":1,"mean_commits":42.0,"dds":0.0,"last_synced_commit":"b998eca3b642b192d31b5fa19e0cf8f8e2f36563"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/interkosmos%2Ffortran-sqlite3","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/interkosmos%2Ffortran-sqlite3/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/interkosmos%2Ffortran-sqlite3/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/interkosmos%2Ffortran-sqlite3/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/interkosmos","download_url":"https://codeload.github.com/interkosmos/fortran-sqlite3/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248843867,"owners_count":21170492,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fortran","fortran-package-manager","fpm","sqlite","sqlite3"],"created_at":"2024-11-08T03:09:43.952Z","updated_at":"2025-04-14T08:10:14.119Z","avatar_url":"https://github.com/interkosmos.png","language":"Fortran","readme":"# fortran-sqlite3\n\n[![Build and Test](https://github.com/interkosmos/fortran-sqlite3/actions/workflows/build.yml/badge.svg)](https://github.com/interkosmos/fortran-sqlite3/actions/workflows/build.yml)\n\nA work-in-progress collection of Fortran 2018 interface bindings to SQLite 3\n(≥ 3.39.0). See [COVERAGE](COVERAGE.md) for an overview of bound functions.\n\n## Build Instructions\n\nMake sure that `libsqlite3` is installed with development headers. On FreeBSD,\nrun:\n\n```\n# pkg install databases/sqlite3\n```\n\nOn Linux:\n\n```\n# apt-get install sqlite3 libsqlite3-0 libsqlite3-dev\n```\n\nOr, build SQLite 3 from source:\n\n```\n$ git clone --depth 1 https://github.com/sqlite/sqlite.git\n$ cd sqlite/\n$ ./configure\n$ make\n$ sudo make install\n```\n\nThen, clone the GitHub repository:\n\n```\n$ git clone --depth 1 https://github.com/interkosmos/fortran-sqlite3\n$ cd fortran-sqlite3/\n```\n\nEither build the library with `fpm` or `make`. Once compiled, link your Fortran\napplication against `libfortran-sqlite3.a` and `-lsqlite3`.\n\n### Fortran Package Manager\n\nSimply execute the Fortran Package Manager:\n\n```\n$ fpm build --profile release\n```\n\nThe output files are written to `build/`.\n\n### make\n\nExecute the provided `Makefile`:\n\n```\n$ make\n```\n\nPass the preprocessor flag `-DSQLITE_ENABLE_COLUMN_METADATA=1` to add interface\nbindings to column meta data functions:\n\n```\n$ make PPFLAGS=\"-DSQLITE_ENABLE_COLUMN_METADATA=1\"\n```\n\nYou may want to override the default compilers by passing the arguments `CC` (C\ncompiler) and `FC` (Fortran compiler). To install the library and the module\nfiles system-wide, for example, to `/opt`, run:\n\n```\n$ make install PREFIX=/opt\n```\n\n## Source-Code Documentation\n\nUse [FORD](https://github.com/Fortran-FOSS-Programmers/ford) to generate the\nsource-code documentation:\n\n```\n$ ford ford.md\n```\n\nThe output files are written to `doc/`.\n\n## Example\n\nThe following SQL schema will be created by the example:\n\n```sql\nCREATE TABLE example (\n    id     INTEGER PRIMARY KEY,\n    string TEXT,\n    value  INTEGER\n);\n```\n\nThe program opens a database `example.sqlite`, creates the table `example`,\ninserts some values, then reads them back in, and prints them to console.\n\n```fortran\n! example.f90\nprogram example\n    use, intrinsic :: iso_c_binding\n    use :: sqlite3\n    implicit none (type, external)\n\n    character(len=:), allocatable :: errmsg\n    integer                       :: rc\n    type(c_ptr)                   :: db\n    type(c_ptr)                   :: stmt\n\n    ! Open SQLite database.\n    rc = sqlite3_open('example.sqlite', db)\n\n    ! Create table.\n    rc = sqlite3_exec(db, \"CREATE TABLE example_table (\" // \u0026\n                          \"id     INTEGER PRIMARY KEY,\" // \u0026\n                          \"string TEXT,\" // \u0026\n                          \"value  INTEGER)\", c_null_ptr, c_null_ptr, errmsg)\n    if (rc /= SQLITE_OK) print '(\"sqlite3_exec(): \", a)', errmsg\n\n    ! Create a prepared statement.\n    rc = sqlite3_prepare_v2(db, \"INSERT INTO example(string, value) VALUES (?, ?)\", stmt)\n\n    ! Bind the values to the statement.\n    rc = sqlite3_bind_text(stmt, 1, 'one')\n    rc = sqlite3_bind_int(stmt, 2, 12345)\n\n    ! Run the statement.\n    rc = sqlite3_step(stmt)\n    if (rc /= SQLITE_DONE) print '(\"sqlite3_step(): failed\")'\n\n    ! Delete the statement.\n    rc = sqlite3_finalize(stmt)\n\n    ! Read values from database.\n    rc = sqlite3_prepare_v2(db, \"SELECT * FROM example\", stmt)\n\n    ! Print rows line by line.\n    do while (sqlite3_step(stmt) /= SQLITE_DONE)\n        call print_values(stmt, 3)\n    end do\n\n    ! Delete the statement.\n    rc = sqlite3_finalize(stmt)\n\n    ! Close SQLite handle.\n    rc = sqlite3_close(db)\ncontains\n    subroutine print_values(stmt, ncols)\n        type(c_ptr), intent(inout) :: stmt\n        integer,     intent(in)    :: ncols\n        integer                    :: col_type\n        integer                    :: i\n\n        do i = 0, ncols - 1\n            col_type = sqlite3_column_type(stmt, i)\n\n            select case (col_type)\n                case (SQLITE_INTEGER)\n                    write (*, '(i12)', advance='no') sqlite3_column_int(stmt, i)\n\n                case (SQLITE_FLOAT)\n                    write (*, '(f0.8)', advance='no') sqlite3_column_double(stmt, i)\n\n                case (SQLITE_TEXT)\n                    write (*, '(a12)', advance='no') sqlite3_column_text(stmt, i)\n\n                case default\n                    write (*, '(\" not implemented\")', advance='no')\n            end select\n        end do\n\n        print *\n    end subroutine print_values\nend program example\n```\n\nIf the library is installed to `/opt`, then compile, link, and run the example\nwith:\n\n```\n$ gfortran -I/opt/include/libfortran-sqlite3 -o example example.f90 /opt/lib/libfortran-sqlite3.a -lsqlite3\n$ ./example\n           1         one       12345\n```\n\n## Fortran Package Manager\n\nYou can add *fortran-sqlite3* as an [fpm](https://github.com/fortran-lang/fpm)\ndependency to your `fpm.toml`:\n\n```toml\n[dependencies]\nfortran-sqlite3 = { git = \"https://github.com/interkosmos/fortran-sqlite3.git\" }\n```\n\n## Compatibility\n\nThe Fortran interfaces to the SQLite functions `sqlite3_bind_text()` and\n`sqlite3_column_text()` support only 8-bit character strings.\n\nThe Fortran wrapper function `sqlite3_bind_text()` selects destructor type\n`SQLITE_TRANSIENT` if argument `destructor` is not passed, in contrast to the\nSQLite default `SQLITE_STATIC`. Therefore, SQLite will make a copy of the given\nvalue. Otherwise, the passed variable could go out of scope before SQLite was\nable to read the string completely, leading to possible data corruption.\n\nThe module `sqlite3_util` contains C interoperability functions/interfaces to\nconvert C char pointer to Fortran allocatable character.\n\n## Licence\n\nISC\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finterkosmos%2Ffortran-sqlite3","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finterkosmos%2Ffortran-sqlite3","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finterkosmos%2Ffortran-sqlite3/lists"}