CApache

1.0.0

Swift Module Maps for Apache, ApachePortableRuntime and APRUtil
modswift/CApache

What's New

Make Apache GREAT again!

2017-05-29T20:41:21Z

CApache

Apache 2 Swift3 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", majorVersion: 0),
  ]
)

Import the CAPR module.

import CAPR
import CAPRUtil

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_initialize()
apr_pool_create_ex(&pool, nil, nil, nil)
apr_dbd_init(pool)
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 }
  
  print("record:")
  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")
    }
  }
}

Who

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.

Description

  • Swift Tools 3.1.0
View More Packages from this Author

Dependencies

  • None
Last updated: Thu Apr 25 2024 01:07:13 GMT-0900 (Hawaii-Aleutian Daylight Time)