From 8f7f0ae5c1ee4d2063b6704416857dc61a11935e Mon Sep 17 00:00:00 2001 From: Anton Batenev Date: Fri, 13 Sep 2013 17:20:05 +0400 Subject: [PATCH] FreeBSD build (must fix #2, #3 also) --- build.sh | 37 ++++++++++++++++++------------------- config.m4 | 2 +- example.php | 20 ++++++++++++++++++++ 3 files changed, 39 insertions(+), 20 deletions(-) diff --git a/build.sh b/build.sh index 20df6a8..af99966 100755 --- a/build.sh +++ b/build.sh @@ -17,10 +17,16 @@ CFLAGS=" \ -DSQLITE_ENABLE_ICU \ -DSQLITE_SOUNDEX \ -DSQLITE_DEFAULT_FOREIGN_KEYS=1 \ - -I/usr/local/include" + -I. -I/usr/local/include" LDFLAGS="-lcrypto -licuuc -licui18n -L/usr/local/lib" +# fix FreeBSD include +UNAME=$(uname) +if [ "x${UNAME}" = "xFreeBSD" ]; then + CFLAGS="${CFLAGS} -include /usr/include/sys/stat.h" +fi + # # Get PHP source code (installed version) # @@ -126,21 +132,15 @@ fi for FILE in "${BUILD_DIR}"/* do cat "${FILE}" | \ - sed -e 's//"sqlcipher3.h"/g' | \ - sed -e 's/pdo_sqlite/pdo_sqlcipher/g' | \ - sed -e 's/php_sqlite3/php_sqlcipher/g' | \ - sed -e 's/sqlite_handle_/sqlcipher_handle_/g' | \ - sed -e 's/sqlite_stmt_methods/sqlcipher_stmt_methods/g' | \ - sed -e 's/PDO_SQLITE/PDO_SQLCIPHER/g' | \ - sed -e 's/HEADER(sqlite)/HEADER(sqlcipher)/g' | \ - sed -e 's/PDO Driver for SQLite 3.x/PDO Driver for SQLCipher/g' | \ - sed -e 's/SQLite Library/SQLCipher Library/g' > \ + sed -e 's/sqlite/sqlcipher/g' | \ + sed -e 's/SQLite/SQLCipher/g' | \ + sed -e 's/PDO_SQLITE/PDO_SQLCIPHER/g' > \ "${FILE}.tmp" if [ $? -ne 0 ]; then exit $? fi - NEW_FILE=$(echo ${FILE} | sed 's/_sqlite/_sqlcipher/') + NEW_FILE=$(echo ${FILE} | sed 's/sqlite/sqlcipher/') mv "${FILE}.tmp" "${NEW_FILE}" if [ $? -ne 0 ]; then @@ -155,16 +155,15 @@ do fi done -# copy unmodified sqlite sources +# magic for sqlite3 api sources cp "${SQLCIPHER_SRC}/sqlite3.c" "${BUILD_DIR}/sqlcipher3.c" -if [ $? -ne 0 ]; then - exit $? -fi - cp "${SQLCIPHER_SRC}/sqlite3.h" "${BUILD_DIR}/sqlcipher3.h" -if [ $? -ne 0 ]; then - exit $? -fi + +for FILE in "${BUILD_DIR}"/sqlcipher3.* +do + sed -rie 's/sqlite3/sqlcipher3/g' "${FILE}" + sed -rie 's/(".*)sqlcipher3(.*")/\1sqlite3\2/g' "${FILE}" +done # # Build pdo_sqlcipher diff --git a/config.m4 b/config.m4 index a96a1ce..74af51d 100644 --- a/config.m4 +++ b/config.m4 @@ -25,7 +25,7 @@ if test "$PHP_PDO_SQLCIPHER" != "no"; then fi AC_MSG_RESULT($pdo_inc_path) - php_pdo_sqlcipher_sources_core="pdo_sqlcipher.c sqlite_driver.c sqlite_statement.c sqlcipher3.c" + php_pdo_sqlcipher_sources_core="pdo_sqlcipher.c sqlcipher_driver.c sqlcipher_statement.c sqlcipher3.c" PHP_NEW_EXTENSION(pdo_sqlcipher, $php_pdo_sqlcipher_sources_core, $ext_shared,,-I$pdo_inc_path) diff --git a/example.php b/example.php index 6ce9f64..fe67899 100644 --- a/example.php +++ b/example.php @@ -73,3 +73,23 @@ if ($result === false) { foreach ($result as $row) { print_r($row); } + +// alter table +$sql = "ALTER TABLE `test` RENAME TO `test2`"; + +if ($pdo->exec($sql) === false) { + $error = $pdo->errorInfo(); + die($error[0] . ": " . $error[2] . PHP_EOL); +} + +// select rows +$result = $pdo->query("SELECT * FROM `test2`"); + +if ($result === false) { + $error = $pdo->errorInfo(); + die($error[0] . ": " . $error[2] . PHP_EOL); +} + +foreach ($result as $row) { + print_r($row); +}