Example #1
0
  // XXX: needs to handle NumberFormatException (on input like 0b2) and needs
  //     a better long guard than ndigits > 11 (this is much to short for
  //     binary for example)
  Object makeInt(Token t) {
    String s = t.getText();
    int radix = 10;
    if (s.startsWith("0x") || s.startsWith("0X")) {
      radix = 16;
      s = s.substring(2, s.length());
    } else if (s.startsWith("0o") || s.startsWith("0O")) {
      radix = 8;
      s = s.substring(2, s.length());
    } else if (s.startsWith("0b") || s.startsWith("0B")) {
      radix = 2;
      s = s.substring(2, s.length());
    } else if (s.startsWith("0")) {
      radix = 8;
    }
    int ndigits = s.length();
    int i = 0;
    while (i < ndigits && s.charAt(i) == '0') i++;
    if ((ndigits - i) > 11) {
      return Py.newInteger(new BigInteger(s, radix));
    }

    long l = Long.valueOf(s, radix).longValue();
    if (l > 0xffffffffl || (l > Integer.MAX_VALUE)) {
      return Py.newInteger(new BigInteger(s, radix));
    }
    return Py.newInteger((int) l);
  }
Example #2
0
  /**
   * Prepare the binding dictionary with the correct datatypes.
   *
   * @param params a non-None list of params
   * @param bindings a dictionary of bindings
   */
  public void normalizeInput(PyObject params, PyObject bindings) throws SQLException {

    if (this.columns == Py.None) {
      return;
    }

    // do nothing with params at the moment
    for (int i = 0, len = this.columns.__len__(), binding = 0; i < len; i++) {
      PyObject column = this.columns.__getitem__(i);
      int colType = column.__getitem__(COLUMN_TYPE).asInt();

      switch (colType) {
        case DatabaseMetaData.procedureColumnIn:
        case DatabaseMetaData.procedureColumnInOut:

          // bindings are Python-indexed
          PyInteger key = Py.newInteger(binding++);

          if (bindings.__finditem__(key) == null) {
            int dataType = column.__getitem__(DATA_TYPE).asInt();
            bindings.__setitem__(key, Py.newInteger(dataType));
          }

          // inputs are JDBC-indexed
          this.inputSet.set(i + 1);
          break;
      }
    }
  }
Example #3
0
  /**
   * Gets the value of the attribute name.
   *
   * @param name
   * @return the attribute for the given name
   */
  public PyObject __findattr_ex__(String name) {

    if ("destinationDataHandler".equals(name)) {
      return Py.java2py(this.destDH);
    } else if ("sourceDataHandler".equals(name)) {
      return Py.java2py(this.sourceDH);
    } else if ("batchsize".equals(name)) {
      return Py.newInteger(this.batchsize);
    } else if ("queuesize".equals(name)) {
      return Py.newInteger(this.queuesize);
    }

    return super.__findattr_ex__(name);
  }
Example #4
0
  /**
   * Initializes the object's namespace.
   *
   * @param dict
   */
  public static void classDictInit(PyObject dict) {

    dict.__setitem__(
        "__version__",
        Py.newString("$Revision: 5206 $").__getslice__(Py.newInteger(11), Py.newInteger(-2), null));
    dict.__setitem__("bcp", new BCPFunc("bcp", 0, 1, 2, zxJDBC.getString("bcp")));
    dict.__setitem__("batchsize", Py.newString(zxJDBC.getString("batchsize")));
    dict.__setitem__("queuesize", Py.newString(zxJDBC.getString("queuesize")));

    // hide from python
    dict.__setitem__("classDictInit", null);
    dict.__setitem__("toString", null);
    dict.__setitem__("PyClass", null);
    dict.__setitem__("getPyClass", null);
    dict.__setitem__("sourceDH", null);
    dict.__setitem__("destDH", null);
  }
 @Override
 public PyObject read(int n) {
   PyType self_type = getType();
   PyObject impl = self_type.lookup("read");
   if (impl != null) {
     return impl.__get__(this, self_type).__call__(Py.newInteger(n));
   } else {
     return super.read(n);
   }
 }
Example #6
0
 private PyObject checkCircularReference(PyObject obj) {
   PyObject ident = null;
   if (markers != null) {
     ident = Py.newInteger(Py.id(obj));
     if (markers.__contains__(ident)) {
       throw Py.ValueError("Circular reference detected");
     }
     markers.__setitem__(ident, obj);
   }
   return ident;
 }
 @Override
 public long seek(long pos, int whence) {
   PyType self_type = getType();
   PyObject impl = self_type.lookup("seek");
   if (impl != null) {
     return impl.__get__(this, self_type)
         .__call__(Py.newLong(pos), Py.newInteger(whence))
         .asLong();
   } else {
     return super.seek(pos, whence);
   }
 }
Example #8
0
  /**
   * Bulkcopy data from one database to another.
   *
   * @param fromTable the table in question on the source database
   * @param where an optional where clause, defaults to '(1=1)' if null
   * @param params optional params to substituted in the where clause
   * @param include the columns to be queried from the source, '*' if None
   * @param exclude the columns to be excluded from insertion on the destination, all if None
   * @param toTable if non-null, the table in the destination db, otherwise the same table name as
   *     the source
   * @param bindings the optional bindings for the destination, this allows morphing of types during
   *     the copy
   * @return the count of the total number of rows bulk copied, -1 if the query returned no rows
   */
  protected PyObject bcp(
      String fromTable,
      String where,
      PyObject params,
      PyObject include,
      PyObject exclude,
      String toTable,
      PyObject bindings) {

    Pipe pipe = new Pipe();
    String _toTable = (toTable == null) ? fromTable : toTable;
    DBSource source = new DBSource(this.source, sourceDH, fromTable, where, include, params);
    DBSink sink = new DBSink(this.destination, destDH, _toTable, exclude, bindings, this.batchsize);

    return pipe.pipe(source, sink).__sub__(Py.newInteger(1));
  }
Example #9
0
 Object unpack(ByteStream buf) {
   int v = (buf.readByte() << 8) | buf.readByte();
   return Py.newInteger(v);
 }
Example #10
0
 Object unpack(ByteStream buf) {
   int v = (buf.readByte() << 8) | buf.readByte();
   if (v > Short.MAX_VALUE) v -= 0x10000;
   return Py.newInteger(v);
 }
Example #11
0
 Object unpack(ByteStream buf) {
   return Py.newInteger(buf.readByte());
 }
Example #12
0
 Object unpack(ByteStream buf) {
   int b = buf.readByte();
   if (b > Byte.MAX_VALUE) b -= 0x100;
   return Py.newInteger(b);
 }
Example #13
0
 final PyObject LShift___int__() {
   return Py.newInteger(7);
 }
Example #14
0
 @ExposedGet(name = "level")
 public PyObject getLevel() {
   return Py.newInteger(level);
 }
Example #15
0
 final PyObject Div___int__() {
   return Py.newInteger(4);
 }
Example #16
0
 Object unpack(ByteStream buf) {
   int v = LEreadInt(buf);
   return Py.newInteger(v);
 }
Example #17
0
 Object unpack(ByteStream buf) {
   return Py.newInteger(BEreadInt(buf));
 }
Example #18
0
 final PyObject FloorDiv___int__() {
   return Py.newInteger(12);
 }