Skip to content
This repository
Browse code

Sqlite: Add option for contributed functions

Closes #6939.

Signed-off-by: Charlie Sharpsteen <source@sharpsteen.net>
  • Loading branch information...
commit 7831ef9c61e374528b95904a517bda4bbaf4f746 1 parent 546fda9
authored August 31, 2011 Sharpie committed September 21, 2011

Showing 1 changed file with 44 additions and 6 deletions. Show diff stats Hide diff stats

  1. 50  Library/Formula/sqlite.rb
50  Library/Formula/sqlite.rb
... ...
@@ -1,16 +1,23 @@
1 1
 require 'formula'
2 2
 
  3
+class SqliteFunctions < Formula
  4
+  url 'http://www.sqlite.org/contrib/download/extension-functions.c?get=25', :using  => NoUnzipCurlDownloadStrategy
  5
+  md5 '3a32bfeace0d718505af571861724a43'
  6
+  version '2010-01-06'
  7
+end
  8
+
3 9
 class Sqlite < Formula
4 10
   homepage 'http://sqlite.org/'
5  
-  url 'http://www.sqlite.org/sqlite-autoconf-3070700.tar.gz'
6  
-  md5 'a98df57053adf4c132b6b7ab59e9f333'
7  
-  version '3.7.7'
  11
+  url 'http://www.sqlite.org/sqlite-autoconf-3070701.tar.gz'
  12
+  md5 '554026fe7fac47b1cf61c18d5fe43419'
  13
+  version '3.7.7.1'
8 14
 
9 15
   def options
10 16
   [
11 17
     ["--with-rtree", "Enables the R*Tree index module"],
12 18
     ["--with-fts", "Enables the FTS Module"],
13  
-    ["--universal", "Build a universal binary."]
  19
+    ["--universal", "Build a universal binary."],
  20
+    ["--with-functions", "Enables more math and string functions for SQL queries."]
14 21
   ]
15 22
   end
16 23
 
@@ -18,8 +25,39 @@ def install
18 25
     ENV.append "CFLAGS", "-DSQLITE_ENABLE_RTREE=1" if ARGV.include? "--with-rtree"
19 26
     ENV.append "CPPFLAGS","-DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_FTS3_PARENTHESIS" if ARGV.include? "--with-fts"
20 27
     ENV.universal_binary if ARGV.build_universal?
21  
-    system "./configure", "--prefix=#{prefix}",
22  
-                          "--disable-dependency-tracking"
  28
+
  29
+    system "./configure", "--prefix=#{prefix}", "--disable-dependency-tracking",
  30
+                          (ARGV.include? "--with-functions") ? "--enable-dynamic-extensions" : ""
23 31
     system "make install"
  32
+
  33
+    if ARGV.include? "--with-functions"
  34
+      d=Pathname.getwd
  35
+      SqliteFunctions.new.brew { mv 'extension-functions.c?get=25', d + 'extension-functions.c' }
  36
+      system ENV.cc, "-fno-common", "-dynamiclib", "extension-functions.c", "-o", "libsqlitefunctions.dylib", *ENV.cflags.split
  37
+      lib.install "libsqlitefunctions.dylib"
  38
+    end
  39
+  end
  40
+
  41
+  if ARGV.include? "--with-functions"
  42
+    def caveats
  43
+      <<-EOS.undent
  44
+        Usage instructions for applications calling the sqlite3 API functions:
  45
+
  46
+          In your application, call sqlite3_enable_load_extension(db,1) to
  47
+          allow loading external libraries.  Then load the library libsqlitefunctions
  48
+          using sqlite3_load_extension; the third argument should be 0.
  49
+          See http://www.sqlite.org/cvstrac/wiki?p=LoadableExtensions.
  50
+          Select statements may now use these functions, as in
  51
+          SELECT cos(radians(inclination)) FROM satsum WHERE satnum = 25544;
  52
+
  53
+        Usage instructions for the sqlite3 program:
  54
+
  55
+          If the program is built so that loading extensions is permitted,
  56
+          the following will work:
  57
+           sqlite> SELECT load_extension('#{lib}/libsqlitefunctions.dylib');
  58
+           sqlite> select cos(radians(45));
  59
+           0.707106781186548
  60
+      EOS
  61
+    end
24 62
   end
25 63
 end

0 notes on commit 7831ef9

Please sign in to comment.
Something went wrong with that request. Please try again.