Swiftpack.co - Package - modswift/CApache


Apache 2 Swift3 Swift4 Swift5 macOS tuxOS

A Swift system library package (C wrapper) for Apache, ApachePortableRuntime and APRUtil. This package is part of the mod_swift effort.

Using the Apache Portable Runtime

Important: This version of the package requires that you install mod_swift. It installs the necessary shims.

Setup your Package.swift to include CApache:

import PackageDescription

let package = Package(
  name: "MyTool",
  dependencies: [
    .Package(url: "git@github.com:modswift/CApache.git", from: "2.0.0"),

Import the CAPR module.

import CAPR
import CAPRUtil

Note: If you are still on Swift 3 or 4.0, use version 1.0.0.

APR Database Example

Access a SQLite3 database using the APR-Util DBD module (zer0 error handling):

let connectString = "OpenGroupware.sqlite3"
let sql = "SELECT company_id, login FROM person"

var pool         : OpaquePointer? = nil
var driverHandle : OpaquePointer? = nil
var con          : OpaquePointer? = nil
var res          : OpaquePointer? = nil

apr_pool_create_ex(&pool, nil, nil, nil)
apr_dbd_get_driver(pool, "sqlite3", &driverHandle)
apr_dbd_open(driverHandle, pool, connectString, &con)

apr_dbd_select(driverHandle, pool, con, &res, sql, 0)

var row : OpaquePointer? = nil
while true {
  let rc = apr_dbd_get_row(driverHandle, pool, res, &row, Int32(-1))
  guard rc == 0 else { break }
  let colCount = apr_dbd_num_cols(driverHandle, res)
  for colIdx in 0..<colCount {
    let name : String
    if let cstr = apr_dbd_get_name(driverHandle, res, colIdx) {
      name = String(cString: cstr)
    else {
      name = "[\(colIdx)]"
    if let cstr = apr_dbd_get_entry(driverHandle, row, colIdx) {
      print("  \(name) = \(String(cString: cstr))")
    else {
      print("  \(name) IS NULL")


mod_swift is brought to you by ZeeZide. We like feedback, GitHub stars, cool contract work, presumably any form of praise you can think of.

There is a #mod_swift channel on the Noze.io Slack.


Stars: 0
Help us keep the lights on



1.0.0 - May 29, 2017