[Pkg-javascript-commits] [node-sqlite3] 01/06: Imported Upstream version 2.1.19+ds1

László Böszörményi gcs at moszumanska.debian.org
Sun Apr 24 08:28:17 UTC 2016


This is an automated email from the git hooks/post-receive script.

gcs pushed a commit to branch master
in repository node-sqlite3.

commit 312f02279429948b5e973a096ec8bd5e286d4d47
Author: Laszlo Boszormenyi (GCS) <gcs at debian.org>
Date:   Sun Apr 24 08:11:36 2016 +0000

    Imported Upstream version 2.1.19+ds1
---
 .gitignore                               |   2 +
 .travis.yml                              |  50 +++++-
 CHANGELOG.md                             |  21 +++
 LICENSE                                  |  33 ++--
 Makefile                                 |   8 +-
 README.md                                |  18 +--
 binding.gyp                              |  28 ----
 build-util/crosswalk-semver-to-module.js |  96 ++++++++++++
 build-util/remake.sh                     |  34 +++++
 build-util/tools.js                      |  88 +++++++++++
 build-util/upload.sh                     |  32 ++++
 build.js                                 | 251 +++++++++++++++++++++++++++++++
 lib/binary_name.js                       |  59 ++++++++
 lib/sqlite3.js                           |  10 +-
 package.json                             |  26 ++--
 src/statement.cc                         |   2 +-
 test/issue-108.test.js                   |  28 ++++
 17 files changed, 714 insertions(+), 72 deletions(-)

diff --git a/.gitignore b/.gitignore
index 57aa6de..b62f417 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,6 +5,8 @@
 *.lo
 *.Makefile
 *.target.gyp.mk
+stage
+lib/binding
 build
 out
 Release
diff --git a/.travis.yml b/.travis.yml
index c248402..960bd00 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,6 +1,48 @@
 language: node_js
+
 node_js:
-  - "0.10"
-  - "0.8"
-  - "0.6"
-before_script: "npm install mocha"
+ - "0.10"
+ - "0.8"
+ - "0.6"
+
+before_install:
+ - sudo apt-get -qq update
+
+install:
+ # test installing from a binary
+ - npm install
+ - npm install mocha
+ - npm test
+
+before_script:
+ - make clean
+
+script:
+ # test source compile with internal libsqlite3
+ - npm install --stage
+ - npm test
+ - sudo apt-get -qq install libsqlite3-dev
+ - make clean
+ # test source compile against external libsqlite3
+ - npm install --build-from-source --sqlite=/usr
+ # output linking details for debugging
+ - ldd lib/binding/*/*/*node
+ - npm test
+ - make clean
+ # node v0.8 and above provide pre-built 32 bit and 64 bit linux binaries
+ # so here we use the 32 bit ones to also test 32 bit builds
+ - export NVER=`node -v`
+ - if [[ "$NVER" != v0.6* ]]; then wget http://nodejs.org/dist/${NVER}/node-${NVER}-linux-x86.tar.gz; fi
+ - if [[ "$NVER" != v0.6* ]]; then tar xf node-${NVER}-linux-x86.tar.gz; fi
+ - if [[ "$NVER" != v0.6* ]]; then export PATH=$(pwd)/node-${NVER}-linux-x86/bin:$PATH; fi
+ - if [[ "$NVER" != v0.6* ]]; then sudo apt-get -y install binutils:i386 cpp:i386 gcc-4.6:i386 g++-4.6:i386 libstdc++6-4.6-dev:i386 | true; fi
+ # test source compile in 32 bit mode with internal libsqlite3
+ - if [[ "$NVER" != v0.6* ]]; then CC=gcc-4.6 CXX=g++-4.6 npm install --build-from-source; fi
+ - if [[ "$NVER" != v0.6* ]]; then ldd lib/binding/*/*/*node; fi
+ - if [[ "$NVER" != v0.6* ]]; then npm test; fi
+ - if [[ "$NVER" != v0.6* ]]; then make clean; fi
+ - if [[ "$NVER" != v0.6* ]]; then sudo apt-get -y install libsqlite3-dev:i386; fi
+ # test source compile in 32 bit mode against external libsqlite3
+ - if [[ "$NVER" != v0.6* ]]; then CC=gcc-4.6 CXX=g++-4.6 npm install --build-from-source --sqlite=/usr; fi
+ - if [[ "$NVER" != v0.6* ]]; then ldd lib/binding/*/*/*node; fi
+ - if [[ "$NVER" != v0.6* ]]; then npm test; fi
\ No newline at end of file
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 08a58de..c2f08d2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,26 @@
 # Changlog
 
+## 2.1.19
+
+Released October 31st, 2013
+
+ - Started respecting `process.env.npm_config_tmp` as location to download binaries
+ - Removed uneeded `progress` dependency
+
+## 2.1.18
+
+Released October 22nd, 2013
+
+ - `node-sqlite3` moved to mapbox github group
+ - Fixed reporting of node-gyp errors
+ - Fixed support for node v0.6.x
+
+## 2.1.17
+ - Minor fixes to binary deployment
+
+## 2.1.16
+ - Support for binary deployment
+
 ## 2.1.15
 
 Released August 7th, 2013
diff --git a/LICENSE b/LICENSE
index 2e4eba8..6c4ce40 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,24 +1,25 @@
-Copyright (c) 2011, Konstantin Käfer <kkaefer at gmail.com>
+Copyright (c) MapBox
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without modification,
 are permitted provided that the following conditions are met:
-    * Redistributions of source code must retain the above copyright notice,
-      this list of conditions and the following disclaimer.
-    * Redistributions in binary form must reproduce the above copyright notice,
-      this list of conditions and the following disclaimer in the documentation
-      and/or other materials provided with the distribution.
-    * Neither the name of "Development Seed" nor the names of its contributors
-      may be used to endorse or promote products derived from this software
-      without specific prior written permission.
+
+- Redistributions of source code must retain the above copyright notice, this
+  list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright notice, this
+  list of conditions and the following disclaimer in the documentation and/or
+  other materials provided with the distribution.
+- Neither the name "MapBox" nor the names of its contributors may be
+  used to endorse or promote products derived from this software without
+  specific prior written permission.
 
 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL Konstantin Käfer BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
-BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
-OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\ No newline at end of file
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\ No newline at end of file
diff --git a/Makefile b/Makefile
index 7924cdd..c986b98 100644
--- a/Makefile
+++ b/Makefile
@@ -1,9 +1,11 @@
 build:
-	node-gyp build
+	npm install --build-from-source
 
 clean:
-	rm -f test/support/big.db*
-	rm -f test/tmp/*
+	rm -f ./lib/node_sqlite3.node
+	rm -rf ./lib/binding/
+	#rm -f ./test/support/big.db*
+	rm -f ./test/tmp/*
 	rm -rf ./deps/sqlite-autoconf-*/
 	rm -rf ./build
 	rm -rf ./out
diff --git a/README.md b/README.md
index 486fd26..bd82065 100644
--- a/README.md
+++ b/README.md
@@ -4,13 +4,13 @@ node-sqlite3 - Asynchronous, non-blocking [SQLite3](http://sqlite.org/) bindings
 
 (Can also run in [node-webkit](https://github.com/rogerwang/node-webkit) if it uses a supported version of Node's engine.)
 
-[![Build Status](https://travis-ci.org/developmentseed/node-sqlite3.png?branch=master)](https://travis-ci.org/developmentseed/node-sqlite3)
+[![Build Status](https://travis-ci.org/mapbox/node-sqlite3.png?branch=master)](https://travis-ci.org/mapbox/node-sqlite3)
 [![npm package version](https://badge.fury.io/js/sqlite3.png)](https://npmjs.org/package/sqlite3)
 
 
 # USAGE
 
-**Note:**   the module must be [installed](#installing) before use.
+**Note:** the module must be [installed](#installing) before use.
 
 ``` js
 var sqlite3 = require('sqlite3').verbose();
@@ -39,9 +39,9 @@ db.close();
 
 * Straightforward query and parameter binding interface
 * Full Buffer/Blob support
-* Extensive [debugging support](https://github.com/developmentseed/node-sqlite3/wiki/Debugging)
-* [Query serialization](https://github.com/developmentseed/node-sqlite3/wiki/Control-Flow) API
-* [Extension support](https://github.com/developmentseed/node-sqlite3/wiki/Extensions)
+* Extensive [debugging support](https://github.com/mapbox/node-sqlite3/wiki/Debugging)
+* [Query serialization](https://github.com/mapbox/node-sqlite3/wiki/Control-Flow) API
+* [Extension support](https://github.com/mapbox/node-sqlite3/wiki/Extensions)
 * Big test suite
 * Written in modern C++ and tested for memory leaks
 
@@ -49,7 +49,7 @@ db.close();
 
 # API
 
-See the [API documentation](https://github.com/developmentseed/node-sqlite3/wiki) in the wiki.
+See the [API documentation](https://github.com/mapbox/node-sqlite3/wiki) in the wiki.
 
 
 # INSTALLING
@@ -58,7 +58,7 @@ You can use [`npm`](https://github.com/isaacs/npm) to download and install:
 
 * The latest `sqlite3` package: `npm install sqlite3`
 
-* GitHub's `master` branch: `npm install https://github.com/developmentseed/node-sqlite3/tarball/master`
+* GitHub's `master` branch: `npm install https://github.com/mapbox/node-sqlite3/tarball/master`
 
 In both cases the module is automatically built with npm's internal version of `node-gyp`,
 and thus your system must meet [node-gyp's requirements](https://github.com/TooTallNate/node-gyp#installation).
@@ -154,9 +154,9 @@ Thanks to [Orlando Vazquez](https://github.com/orlandov),
 [Eric Fredricksen](https://github.com/grumdrig) and
 [Ryan Dahl](https://github.com/ry) for their SQLite bindings for node, and to mraleph on Freenode's #v8 for answering questions.
 
-Development of this module is sponsored by [Development Seed](http://developmentseed.org/).
+Development of this module is sponsored by [MapBox](http://mapbox.org/).
 
 
 # LICENSE
 
-`node-sqlite3` is [BSD licensed](https://github.com/developmentseed/node-sqlite3/raw/master/LICENSE).
+`node-sqlite3` is [BSD licensed](https://github.com/mapbox/node-sqlite3/raw/master/LICENSE).
diff --git a/binding.gyp b/binding.gyp
index 12a3704..4a4547e 100644
--- a/binding.gyp
+++ b/binding.gyp
@@ -3,17 +3,6 @@
   'variables': {
       'sqlite%':'internal',
   },
-  'conditions': [
-      ['OS=="win"', {
-        'variables': {
-          'copy_command%': 'copy',
-        },
-      },{
-        'variables': {
-          'copy_command%': 'cp',
-        },
-      }]
-  ],
   'targets': [
     {
       'target_name': 'node_sqlite3',
@@ -37,23 +26,6 @@
         'src/node_sqlite3.cc',
         'src/statement.cc'
       ],
-    },
-    {
-      'target_name': 'action_after_build',
-      'type': 'none',
-      'dependencies': [ 'node_sqlite3' ],
-      'actions': [
-        {
-          'action_name': 'move_node_module',
-          'inputs': [
-            '<@(PRODUCT_DIR)/node_sqlite3.node'
-          ],
-          'outputs': [
-            'lib/node_sqlite3.node'
-          ],
-          'action': ['<@(copy_command)', '<@(PRODUCT_DIR)/node_sqlite3.node', 'lib/node_sqlite3.node']
-        }
-      ]
     }
   ]
 }
diff --git a/build-util/crosswalk-semver-to-module.js b/build-util/crosswalk-semver-to-module.js
new file mode 100644
index 0000000..54b00ed
--- /dev/null
+++ b/build-util/crosswalk-semver-to-module.js
@@ -0,0 +1,96 @@
+var https = require("https");
+var http = require("http");
+var fs   = require("fs");
+var url = require('url');
+var semver = require('semver');
+
+var cross = {};
+
+// https://github.com/developmentseed/node-sqlite3/wiki/Binaries
+
+var template = 'https://raw.github.com/joyent/node/v{VERSION}/src/';
+
+var sortObjectByKey = function(obj){
+    var keys = [];
+    var sorted_obj = {};
+    for(var key in obj){
+        if(obj.hasOwnProperty(key)){
+            keys.push(key);
+        }
+    }
+    // sort keys
+    keys.sort(function(a,b) {
+      if (semver.gt(a, b)) {
+        return 1
+      }
+      return -1;
+    });
+    len = keys.length;
+
+    for (i = 0; i < len; i++)
+    {
+      key = keys[i];
+      sorted_obj[key] = obj[key];
+    }
+    return sorted_obj;
+};
+
+function get(ver,callback) {
+  var header = 'node.h';
+  if (semver.gt(ver, 'v0.11.4')) {
+    // https://github.com/joyent/node/commit/44ed42bd971d58b294222d983cfe2908e021fb5d#src/node_version.h
+    header = 'node_version.h';
+  }
+  var path = template.replace('{VERSION}',ver) + header;
+  var uri = url.parse(path);
+  https.get(uri, function(res) {
+      if (res.statusCode != 200) {
+        throw new Error("server returned " + res.statusCode + ' for: ' + path);
+      }
+      res.setEncoding('utf8');
+      var body = '';
+      res.on('data', function (chunk) {
+        body += chunk;
+      });
+      res.on('end',function(err) {
+        var term = 'define NODE_MODULE_VERSION'
+        var idx = body.indexOf(term);
+        var following = body.slice(idx);
+        var end = following.indexOf('\n');
+        var value = following.slice(term.length,end).trim();
+        if (value[0] === '(' && value[value.length-1] == ')') {
+          value = value.slice(1,value.length-1);
+        } else if (value.indexOf(' ') > -1) {
+          value = value.slice(0,value.indexOf(' '));
+        }
+        var int_val = +value;
+        cross[ver] = int_val;
+        return callback(null,ver,int_val);
+      })
+    });
+}
+
+process.on('exit', function(err) {
+    var sorted = sortObjectByKey(cross);
+    console.log(sorted);
+})
+
+var versions_doc = 'http://nodejs.org/dist/npm-versions.txt';
+http.get(url.parse(versions_doc), function(res) {
+    if (res.statusCode != 200) {
+      throw new Error("server returned " + res.statusCode + ' for: ' + versions_doc);
+    }
+    res.setEncoding('utf8');
+    var body = '';
+    res.on('data', function (chunk) {
+      body += chunk;
+    });
+    res.on('end',function(err) {
+      var lines = body.split('\n').map(function(line) { return line.split(' ')[0].slice(1); }).filter(function(line) { return (line.length && line != 'node'); });
+      lines.forEach(function(ver) {
+          get(ver,function(err,version,result) {
+            cross[version] = result;
+          });
+      });
+    });
+});
\ No newline at end of file
diff --git a/build-util/remake.sh b/build-util/remake.sh
new file mode 100755
index 0000000..2ff4e66
--- /dev/null
+++ b/build-util/remake.sh
@@ -0,0 +1,34 @@
+export ROOTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+
+export UNAME=$(uname -s);
+
+cd $ROOTDIR
+cd ../
+
+if [ ${UNAME} = 'Darwin' ]; then
+    # note: requires FAT (duel-arch) node installed via .pkg
+    npm install --stage --target_arch=ia32
+    npm install --stage --target_arch=ia32 --debug
+    npm install --stage --target_arch=x64
+    npm install --stage --target_arch=x64 --debug
+
+elif [ ${UNAME} = 'Linux' ]; then
+    rm -rf ./bin/linux-*
+    apt-get -y update
+    apt-get -y install git make build-essential
+    git clone https://github.com/creationix/nvm.git ~/.nvm
+    source ~/.nvm/nvm.sh
+    nvm install 0.10
+    npm install -g node-gyp
+    node ./build.js --target_arch=x64
+    # now do 32 bit
+    NVER=`node -v`
+    wget http://nodejs.org/dist/${NVER}/node-${NVER}-linux-x86.tar.gz
+    tar xf node-${NVER}-linux-x86.tar.gz
+    export PATH=$(pwd)/node-${NVER}-linux-x86/bin:$PATH
+    # ignore: 
+    # dependency problems - leaving unconfigure  gcc-4.6:i386 g++-4.6:i386 libstdc++6-4.6-dev:i386
+    # E: Sub-process /usr/bin/dpkg returned an error code (1)
+    apt-get -y install binutils:i386 cpp:i386 gcc-4.6:i386 g++-4.6:i386 libstdc++6-4.6-dev:i386 | true
+    CC=gcc-4.6 CXX=g++-4.6 node ./build.js --target_arch=ia32    
+fi
\ No newline at end of file
diff --git a/build-util/tools.js b/build-util/tools.js
new file mode 100644
index 0000000..896f779
--- /dev/null
+++ b/build-util/tools.js
@@ -0,0 +1,88 @@
+var http = require('http');
+var url = require('url');
+
+function download(from,options,callback) {
+    var options = options || {};
+    var uri = url.parse(from);
+    var req = http.request(uri);
+    req.on('response', function(res){
+        // needed for end to be called
+        res.resume();
+        if (res.statusCode !== 200) {
+            return callback(new Error('Server returned '+ res.statusCode));
+        }
+        function returnBuffer() {
+            // todo - use http://nodejs.org/api/buffer.html#buffer_class_method_buffer_concat_list_totallength
+            for (var length = 0, i = 0; i < out.length; ++i) {
+                length += out[i].length;
+            }
+            var result = new Buffer(length);
+            for (var pos = 0, j = 0; j < out.length; ++j) {
+                out[j].copy(result, pos);
+                pos += out[j].length;
+            }
+            return callback(null,result);
+        }
+        var out = [];
+        res.on('data', function(chunk) {
+            out.push(chunk);
+        });
+        res.on('end', function(){
+            returnBuffer();
+        });
+        res.on('close', function(){
+            returnBuffer();
+        });
+    });
+    req.on('error', function(err){
+        callback(err);
+    });
+    req.end();
+}
+
+
+function parse_args(_args, opts) {
+    // first split them like npm returns
+    var args = [];
+    _args.forEach(function(a) {
+        var parts = a.split('=');
+        parts.forEach(function(p) {
+            args.push(p);
+        })
+    })
+    // respect flags passed to npm install
+    if (process.env.npm_config_argv) {
+        var argv_obj = JSON.parse(process.env.npm_config_argv);
+        args = args.concat(argv_obj.cooked.slice(1))
+    }
+    var debug = (args.indexOf('--debug') > -1);
+    if (debug) opts.configuration = 'Debug';
+
+    opts.stage = (args.indexOf('--stage') > -1);
+    if (opts.stage) {
+        opts.force = true;
+    } else {
+        var from_source = args.indexOf('--build-from-source');
+        if ( from_source > -1) {
+            // no specific module name passed
+            var next_arg = args[from_source+1];
+            if (!next_arg || next_arg.indexOf('--') <= 0) {
+                opts.force = true;
+            } else if (next_arg == 'sqlite3'){
+                opts.force = true; 
+            }
+        }
+    }
+    var target_arch = args.indexOf('--target_arch');
+    if (target_arch > -1) {
+        var next_arg = args[target_arch+1];
+        if (next_arg && next_arg.indexOf('--') < 0) {
+            opts.target_arch = next_arg;
+        }
+    }
+    opts.args = args;
+    return opts;
+}
+
+module.exports.parse_args = parse_args;
+module.exports.download = download;
\ No newline at end of file
diff --git a/build-util/upload.sh b/build-util/upload.sh
new file mode 100755
index 0000000..9d62c54
--- /dev/null
+++ b/build-util/upload.sh
@@ -0,0 +1,32 @@
+export ROOTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+
+export DRY_RUN="--dry-run"
+export PATTERN="*.*"
+export CHECK_MD5="--no-check-md5"
+
+function make_shas {
+	for i in $(ls *.tar.gz); do
+	shasum_file="${i//.tar.gz/.sha1.txt}";
+	if [ ! -f "${shasum_file}" ]; then
+		echo generating "${shasum_file}"
+		shasum $i | awk '{print $1}' > "${shasum_file}"
+	fi
+	done
+}
+
+cd ${ROOTDIR}/../stage/
+if [ -d Debug ]; then
+cd Debug
+make_shas
+../../../s3cmd/s3cmd sync --acl-public ${CHECK_MD5} ./${PATTERN} s3://node-sqlite3/Debug/ ${DRY_RUN}
+cd ../
+fi
+
+if [ -d Release ]; then
+cd Release
+make_shas
+../../../s3cmd/s3cmd sync --acl-public ${CHECK_MD5} ./${PATTERN} s3://node-sqlite3/Release/ ${DRY_RUN}
+cd ../
+fi
+
+#../../s3cmd/s3cmd ls s3://node-sqlite3/
diff --git a/build.js b/build.js
new file mode 100755
index 0000000..2307232
--- /dev/null
+++ b/build.js
@@ -0,0 +1,251 @@
+#!/usr/bin/env node
+
+/*
+TODO
+ - verbose/quiet mode
+ - travis/nvm/32bit auto-build and post to s3 for linux
+ - cloudfront + logging
+ - script to check for acl-public
+ - use require() to support node_modules location of binary?
+ - consider json config for configuring build and for handling routing remotely
+ - drop tar.gz - use node-tar directly - https://github.com/isaacs/node-tar/issues/11
+*/
+
+var package_json = require('./package.json');
+var Binary = require('./lib/binary_name.js').Binary;
+var util = require('./build-util/tools.js');
+var mkdirp = require('mkdirp');
+var targz = require('tar.gz');
+var cp = require('child_process');
+var fs = require('fs');
+var path = require('path');
+var os = require('os');
+var crypto = require('crypto');
+
+var opts = {
+    name: 'node_sqlite3',
+    force: false,
+    stage: false,
+    configuration: 'Release',
+    target_arch: process.arch,
+    platform: process.platform,
+    uri: 'http://node-sqlite3.s3.amazonaws.com/',
+    tool: 'node-gyp',
+    paths: {}
+}
+
+function log(msg) {
+    console.log('['+package_json.name+']: ' + msg);
+}
+
+// only for dev
+function log_debug(msg) {
+    //log(msg);
+}
+
+function done(err) {
+    if (err) {
+        log(err);
+        process.exit(1);
+    }
+    process.exit(0);
+}
+
+function test(opts,try_build,callback) {
+    fs.statSync(opts.paths.runtime_module_path);
+    var args = [];
+    var shell_cmd;
+    var arch_names = {
+        'ia32':'-i386',
+        'x64':'-x86_64'
+    }
+    if (process.platform === 'darwin' && arch_names[opts.target_arch]) {
+        shell_cmd = 'arch';
+        args.push(arch_names[opts.target_arch]);
+        args.push(process.execPath);
+    } else if (process.arch == opts.target_arch) {
+        shell_cmd = process.execPath;
+    }
+    if (!shell_cmd) {
+        // system we cannot test on - likely since we are cross compiling
+        log("Skipping testing binary for " + process.target_arch);
+        return callback();
+    }
+    args.push('lib/sqlite3');
+    cp.execFile(shell_cmd, args, function(err, stdout, stderr) {
+        if (err || stderr) {
+            var output = err.message || stderr;
+            log('Testing the binary failed: "' + output + '"');
+            if (try_build) {
+                log('Attempting source compile...');
+                build(opts,callback);
+            }
+        } else {
+            log('Sweet: "' + opts.binary.filename() + '" is valid, node-sqlite3 is now installed!');
+            return callback();
+        }
+    });
+}
+
+function build(opts,callback) {
+    var shell_cmd = opts.tool;
+    if (opts.tool == 'node-gyp' && process.platform === 'win32') {
+        shell_cmd = 'node-gyp.cmd';
+    }
+    var shell_args = ['rebuild'].concat(opts.args);
+    var cmd = cp.spawn(shell_cmd,shell_args, {cwd: undefined, env: process.env, customFds: [ 0, 1, 2]});
+    cmd.on('error', function (err) {
+        if (err) {
+            return callback(new Error("Failed to execute '" + shell_cmd + ' ' + shell_args.join(' ') + "' (" + err + ")"));
+        }
+    });
+    // exit not close to support node v0.6.x
+    cmd.on('exit', function (code) {
+        if (code !== 0) {
+            return callback(new Error("Failed to execute '" + shell_cmd + ' ' + shell_args.join(' ') + "' (" + code + ")"));
+        }
+        move(opts,callback);
+    });
+}
+
+function tarball(opts,callback) {
+    var source = path.dirname(opts.paths.staged_module_file_name);
+    log('Compressing: ' + source + ' to ' + opts.paths.tarball_path);
+    new targz(9).compress(source, opts.paths.tarball_path, function(err) {
+        if (err) return callback(err);
+        log('Versioned binary staged for upload at ' + opts.paths.tarball_path);
+        var sha1 = crypto.createHash('sha1');
+        fs.readFile(opts.paths.tarball_path,function(err,buffer) {
+            if (err) return callback(err);
+            sha1.update(buffer);
+            log('Writing shasum at ' + opts.paths.tarball_shasum);
+            fs.writeFile(opts.paths.tarball_shasum,sha1.digest('hex'),callback);
+        });
+    });
+}
+
+function move(opts,callback) {
+    try {
+        fs.statSync(opts.paths.build_module_path);
+    } catch (ex) {
+        return callback(new Error('Build succeeded but target not found at ' + opts.paths.build_module_path));
+    }
+    try {
+        mkdirp.sync(path.dirname(opts.paths.runtime_module_path));
+        log('Created: ' + path.dirname(opts.paths.runtime_module_path));
+    } catch (err) {
+        log_debug(err);
+    }
+    fs.renameSync(opts.paths.build_module_path,opts.paths.runtime_module_path);
+    if (opts.stage) {
+        try {
+            mkdirp.sync(path.dirname(opts.paths.staged_module_file_name));
+            log('Created: ' + path.dirname(opts.paths.staged_module_file_name))
+        } catch (err) {
+            log_debug(err);
+        }
+        fs.writeFileSync(opts.paths.staged_module_file_name,fs.readFileSync(opts.paths.runtime_module_path));
+        // drop build metadata into build folder
+        var metapath = path.join(path.dirname(opts.paths.staged_module_file_name),'build-info.json');
+        // more build info
+        opts.date = new Date();
+        opts.node_features = process.features;
+        opts.versions = process.versions;
+        opts.config = process.config;
+        opts.execPath = process.execPath;
+        fs.writeFileSync(metapath,JSON.stringify(opts,null,2));
+        tarball(opts,callback);
+    } else {
+        log('Installed in ' + opts.paths.runtime_module_path + '');
+        test(opts,false,callback);
+    }
+}
+
+function rel(p) {
+    return path.relative(process.cwd(),p);
+}
+
+var opts = util.parse_args(process.argv.slice(2),opts);
+opts.binary = new Binary(opts);
+var versioned = opts.binary.getRequirePath();
+opts.paths.runtime_module_path = rel(path.join(__dirname, 'lib', versioned));
+opts.paths.runtime_folder = rel(path.join(__dirname, 'lib', 'binding',opts.binary.configuration));
+var staged_module_path = path.join(__dirname, 'stage', opts.binary.getModuleAbi(), opts.binary.getBasePath());
+opts.paths.staged_module_file_name = rel(path.join(staged_module_path,opts.binary.filename()));
+opts.paths.build_module_path = rel(path.join(__dirname, 'build', opts.binary.configuration, opts.binary.filename()));
+opts.paths.tarball_path = rel(path.join(__dirname, 'stage', opts.binary.configuration, opts.binary.getArchivePath()));
+opts.paths.tarball_shasum = opts.paths.tarball_path.replace(opts.binary.compression(),'.sha1.txt');
+
+if (!{ia32: true, x64: true, arm: true}.hasOwnProperty(opts.target_arch)) {
+    return done(new Error('Unsupported (?) architecture: '+ opts.target_arch+ ''));
+}
+
+if (opts.force) {
+    build(opts,done);
+} else {
+    try {
+        test(opts,true,done);
+    } catch (ex) {
+        var from = opts.binary.getRemotePath();
+        var tmpdirbase = '/tmp/';
+        if (process.env.npm_config_tmp) {
+            tmpdirbase = process.env.npm_config_tmp
+        } else if (os.tmpdir) {
+            tmpdirbase = os.tmpdir();
+        }
+        var tmpdir = path.join(tmpdirbase,'node-sqlite3-'+opts.binary.configuration);
+        try {
+            mkdirp.sync(tmpdir);
+        } catch (err) {
+            log_debug(err);
+        }
+
+        log('Checking for ' + from);
+        util.download(from,{progress:false}, function(err,buffer) {
+            if (err) {
+                log(from + ' not found, falling back to source compile (' + err + ')');
+                return build(opts,done);
+            }
+            // calculate shasum of tarball
+            var sha1 = crypto.createHash('sha1');
+            sha1.update(buffer);
+            var actual_shasum = sha1.digest('hex');
+
+            // write local tarball now to make debugging easier if following checks fail
+            var tmpfile = path.join(tmpdir,path.basename(from));
+            fs.writeFile(tmpfile,buffer,function(err) {
+                if (err) return done(err);
+                log('Downloaded to: '+ tmpfile);
+                // fetch shasum expected value
+                var from_shasum = from.replace(opts.binary.compression(),'.sha1.txt');
+                log('Checking for ' + from_shasum);
+                util.download(from_shasum,{progress:false},function(err,expected_shasum_buffer) {
+                    if (err) {
+                        log(from_shasum + ' not found, skipping shasum check (' + err + ')');
+                        return done();
+                    } else {
+                        // now check shasum match
+                        var expected = expected_shasum_buffer.toString().trim();
+                        if (expected !== actual_shasum) {
+                            return done(new Error("shasum does not match between remote and local: " + expected + ' ' + actual_shasum));
+                        } else {
+                            log('Sha1sum matches! ' + expected);
+                            // we are good: continue
+                            log('Extracting to ' + opts.paths.runtime_folder);
+                            new targz().extract(tmpfile, opts.paths.runtime_folder, function(err) {
+                                if (err) return done(err);
+                                try {
+                                    return test(opts,true,done);
+                                } catch (ex) {
+                                    // Stat failed
+                                    log(opts.paths.runtime_folder + ' not found, falling back to source compile');
+                                    return build(opts,done);
+                                }
+                            });
+                        }
+                    }
+                });
+            });
+        });
+    }
+}
diff --git a/lib/binary_name.js b/lib/binary_name.js
new file mode 100644
index 0000000..84a63c6
--- /dev/null
+++ b/lib/binary_name.js
@@ -0,0 +1,59 @@
+
+var path = require('path');
+
+var Binary = function(options) {
+  var options = options || {};
+  var package_json = options.package_json || require('../package.json');
+  this.name = options.name || 'binding';
+  this.configuration = options.configuration || 'Release';
+  this.uri = options.uri || 'http://'+this.name+'.s3.amazonaws.com/';
+  this.module_maj_min = package_json.version.split('.').slice(0,2).join('.');
+  this.module_abi = package_json.abi;
+  this.platform = options.platform || process.platform;
+  this.target_arch = options.target_arch || process.arch;
+  if (process.versions.modules) {
+    // added in >= v0.10.4 and v0.11.7
+    // https://github.com/joyent/node/commit/ccabd4a6fa8a6eb79d29bc3bbe9fe2b6531c2d8e
+    this.node_abi = 'node-v' + (+process.versions.modules);
+  } else {
+    this.node_abi = 'v8-' + process.versions.v8.split('.').slice(0,2).join('.');
+  }
+}
+
+Binary.prototype.filename = function() {
+    return this.name + '.node';
+}
+
+Binary.prototype.compression = function() {
+    return '.tar.gz';
+}
+
+Binary.prototype.getBasePath = function() {
+    return this.node_abi
+           + '-' + this.platform
+           + '-' + this.target_arch;
+}
+
+Binary.prototype.getRequirePath = function(configuration) {
+    return './' + path.join('binding',
+        configuration || this.configuration,
+        this.getBasePath(),
+        this.filename());
+}
+
+Binary.prototype.getModuleAbi = function() {
+    return this.name + '-v' + this.module_maj_min + '.' + this.module_abi;
+}
+
+Binary.prototype.getArchivePath = function() {
+    return this.getModuleAbi()
+           + '-'
+           + this.getBasePath()
+           + this.compression();
+}
+
+Binary.prototype.getRemotePath = function() {
+    return this.uri+this.configuration+'/'+this.getArchivePath();
+}
+
+module.exports.Binary = Binary;
\ No newline at end of file
diff --git a/lib/sqlite3.js b/lib/sqlite3.js
index 62541cf..f7506c2 100644
--- a/lib/sqlite3.js
+++ b/lib/sqlite3.js
@@ -1,4 +1,12 @@
-var sqlite3 = module.exports = exports = require('./node_sqlite3.node');
+var Binary = require('./binary_name.js').Binary;
+var binary = new Binary({name:'node_sqlite3'});
+var binding;
+try {
+    binding = require(binary.getRequirePath('Debug'));
+} catch (err) {
+    binding = require(binary.getRequirePath('Release'));
+}
+var sqlite3 = module.exports = exports = binding;
 var path = require('path');
 var util = require('util');
 var EventEmitter = require('events').EventEmitter;
diff --git a/package.json b/package.json
index af7f054..24216d7 100644
--- a/package.json
+++ b/package.json
@@ -1,23 +1,23 @@
 {
     "name": "sqlite3",
     "description": "Asynchronous, non-blocking SQLite3 bindings",
-    "version": "2.1.15",
-    "homepage": "http://github.com/developmentseed/node-sqlite3",
+    "version": "2.1.19",
+    "abi":"a",
+    "homepage": "http://github.com/mapbox/node-sqlite3",
     "author": {
-        "name": "Development Seed",
-        "url": "http://developmentseed.org/",
-        "email": "info at developmentseed.org"
+        "name": "MapBox",
+        "url": "https://mapbox.com/"
     },
     "contributors": [
         "Konstantin Käfer <mail at kkaefer.com>",
-        "Dane Springmeyer <dane at developmentseed.org>",
-        "Will White <will at developmentseed.org>",
+        "Dane Springmeyer <dane at mapbox.com>",
+        "Will White <will at mapbox.com>",
         "Orlando Vazquez <ovazquez at gmail.com>",
         "Artem Kustikov <kustikoff at gmail.com>",
         "Eric Fredricksen <efredricksen at gmail.com>",
         "John Wright <mrjjwright at gmail.com>",
         "Ryan Dahl <ry at tinyclouds.org>",
-        "Tom MacWright <tom at developmentseed.org>",
+        "Tom MacWright <tom at mapbox.com>",
         "Carter Thaxton <carter.thaxton at gmail.com>",
         "Audrius Kažukauskas <audrius at neutrino.lt>",
         "Johannes Schauer <josch at pyneo.org>",
@@ -27,12 +27,18 @@
     ],
     "repository": {
         "type": "git",
-        "url": "git://github.com/developmentseed/node-sqlite3.git"
+        "url": "git://github.com/mapbox/node-sqlite3.git"
     },
+    "dependencies": {
+        "mkdirp":"~0.3.5",
+        "tar.gz": "~0.1.1"
+    },
+    "bundledDependencies":["mkdirp","tar.gz","progress"],
     "engines": {
-        "node": ">= 0.6.13 && < 0.11.0"
+        "node": ">= 0.6.13 < 0.11.0"
     },
     "scripts": {
+        "install": "node build.js",
         "pretest": "node test/support/createdb.js",
         "test": "mocha -R spec --timeout 200000"
     },
diff --git a/src/statement.cc b/src/statement.cc
index 1ed3de4..04a0d79 100644
--- a/src/statement.cc
+++ b/src/statement.cc
@@ -215,7 +215,7 @@ template <class T> T* Statement::Bind(const Arguments& args, int start, int last
                 baton->parameters.push_back(BindParameter(array->Get(i), pos));
             }
         }
-        else if (!args[start]->IsObject() || args[start]->IsRegExp() || args[start]->IsDate()) {
+        else if (!args[start]->IsObject() || args[start]->IsRegExp() || args[start]->IsDate() || Buffer::HasInstance(args[start])) {
             // Parameters directly in array.
             // Note: bind parameters start with 1.
             for (int i = start, pos = 1; i < last; i++, pos++) {
diff --git a/test/issue-108.test.js b/test/issue-108.test.js
new file mode 100644
index 0000000..2ea69a3
--- /dev/null
+++ b/test/issue-108.test.js
@@ -0,0 +1,28 @@
+var sqlite3 = require('..'),
+    assert = require('assert');
+
+describe('buffer', function() {
+    var db;
+    // before(function() {
+    // });
+
+    it('should insert blobs', function(done) {
+        db = new sqlite3.Database(':memory:');
+        db.serialize(function () {
+
+            db.run("CREATE TABLE lorem (info BLOB)");
+            var stmt = db.prepare("INSERT INTO lorem VALUES (?)");
+
+            stmt.on('error', function (err) {
+                throw err;
+            });
+
+            var buff = new Buffer(2);
+            stmt.run('a');
+            stmt.finalize();
+        });
+
+        db.close(done);
+
+    });
+});

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/collab-maint/node-sqlite3.git



More information about the Pkg-javascript-commits mailing list