Пример #1
0
const dtext * OCI_API OCI_ElemGetString2(OCI_Library *pOCILib, OCI_Elem *elem)
{
    const dtext *str  = NULL;
    boolean res       = FALSE;

    OCI_CHECK_PTR(pOCILib, OCI_IPC_ELEMENT, elem, NULL);

    if (elem->typinf->cols[0].type != OCI_CDT_TEXT) {
       QoreStringNode* desc = new QoreStringNode("cannot retrieve a text value for element '");
       if (elem->typinf->schema) {
	  desc->concat(elem->typinf->schema);
	  desc->concat('.');
       }
       desc->sprintf("%s' of type '%s'", elem->typinf->name, OCI_GetColumnTypeName(elem->typinf->cols[0].type));
       return FALSE;
    }
    
    if (elem->handle != NULL)
    {
        res = TRUE;

        str = (dtext *) OCI_StringFromStringPtr(pOCILib, (OCIString *) elem->handle,
                                                &elem->buf, &elem->buflen);
    }

    OCI_RESULT(pOCILib, res);

    return str;    
}
Пример #2
0
boolean OCI_API OCI_ElemSetString2(OCI_Library *pOCILib, OCI_Elem *elem, const dtext *value, ExceptionSink* xsink)
{
    boolean res  = TRUE;

    OCI_CHECK_PTR(pOCILib, OCI_IPC_ELEMENT, elem, FALSE);
    if (elem->typinf->cols[0].type != OCI_CDT_TEXT) {
       QoreStringNode* desc = new QoreStringNode("cannot bind a string value to element '");
       if (elem->typinf->schema) {
	  desc->concat(elem->typinf->schema);
	  desc->concat('.');
       }
       desc->sprintf("%s' of type '%s'", elem->typinf->name, OCI_GetColumnTypeName(elem->typinf->cols[0].type));
       return FALSE;
    }

    if (value == NULL)
    {
        res = OCI_ElemSetNull2(pOCILib, elem);
    }
    else
    {
        res = OCI_StringToStringPtr(pOCILib, (OCIString **) &elem->handle, 
                                    elem->con->err, (void *) value, 
                                    &elem->buf, &elem->buflen, xsink);

        OCI_ElemSetNullIndicator(elem, OCI_IND_NOTNULL);
    }

    OCI_RESULT(pOCILib, res);

    return res;
}
void getQoreException(java::lang::Throwable *t, ExceptionSink &xsink) {
   //fprintf(stderr, "Unhandled Java exception %p:\n", t);

   //fprintf(stderr, "%s\n", str.getBuffer());

   QoreStringNode *desc = getJavaExceptionMessage(t);

   // get stack trace
   JArray<java::lang::StackTraceElement *> *stack = t->getStackTrace();
   
   java::lang::StackTraceElement **e = elements(stack);
   for (int i = 0; i < stack->length; ++i) {
      QoreString file, cls, meth;
      getQoreString(e[i]->getFileName(), file);
      getQoreString(e[i]->getClassName(), cls);
      getQoreString(e[i]->getMethodName(), meth);

      int line = e[i]->getLineNumber();

      desc->sprintf("\n  %s:%d: %s::%s() (%s)", file.getBuffer(), line > 0 ? line : 0, cls.getBuffer(), meth.getBuffer(), e[i]->isNativeMethod() ? "native" : "java");
   }

   while ((t = t->getCause())) {
      desc->concat("\ncaused by: ");
      SimpleRefHolder<QoreStringNode> ndesc(getJavaExceptionMessage(t));
      desc->concat(*ndesc, &xsink);
   }

   xsink.raiseException("JAVA-EXCEPTION", desc);
}
Пример #4
0
   // always generate a Host header pointing to the host hosting the resource, not the proxy
   // (RFC 2616 is not totally clear on this, but other clients do it this way)
   DLLLOCAL AbstractQoreNode* getHostHeaderValue() {
      if (connection.port == 80)
	 return new QoreStringNode(connection.host.c_str());

      QoreStringNode* str = new QoreStringNode;
      str->concat(connection.host);
      if (connection.port)
	 str->sprintf(":%d", connection.port);
      return str;
   }
Пример #5
0
/* ------------------------------------------------------------------------ *
 * OCI_ElemSetLob
 * ------------------------------------------------------------------------ */
boolean OCI_API OCI_ElemSetLob2(OCI_Library *pOCILib, OCI_Elem *elem, OCI_Lob *value, ExceptionSink* xsink)
{
    boolean res  = TRUE;

    OCI_CHECK_PTR(pOCILib, OCI_IPC_ELEMENT, elem, FALSE);

    if (elem->typinf->cols[0].type != OCI_CDT_LOB) {
       QoreStringNode* desc = new QoreStringNode("cannot bind a lob value to element '");
       if (elem->typinf->schema) {
	  desc->concat(elem->typinf->schema);
	  desc->concat('.');
       }
       desc->sprintf("%s' of type '%s'", elem->typinf->name, OCI_GetColumnTypeName(elem->typinf->cols[0].type));
       return FALSE;
    }
  
    if (value == NULL)
    {
        res = OCI_ElemSetNull2(pOCILib, elem);
    }
    else
    {
        if (elem->obj == NULL)
        {
            OCI_LobInit(pOCILib, elem->con, (OCI_Lob **) &elem->obj,
                        (OCILobLocator *) elem->handle,
                        elem->typinf->cols[0].subtype, xsink);
        }

        if (elem->obj != NULL)
        {
	   res = OCI_LobAssign(pOCILib, (OCI_Lob *) elem->obj, value, xsink);

            if (res == TRUE)
            {
                OCI_ElemSetNullIndicator(elem, OCI_IND_NOTNULL);

                elem->handle = ((OCI_Lob *) elem->obj)->handle;
            }
        }
    }

    OCI_RESULT(pOCILib, res);

    return res;
}
Пример #6
0
// static function
QoreHashNode *QoreException::getStackHash(int type, const char *class_name, const char *code, const QoreProgramLocation& loc) {
   QoreHashNode *h = new QoreHashNode;

   QoreStringNode *str = new QoreStringNode;
   if (class_name)
      str->sprintf("%s::", class_name);
   str->concat(code);

   //printd(5, "QoreException::getStackHash() %s at %s:%d-%d src: %s+%d\n", str->getBuffer(), loc.file ? loc.file : "n/a", loc.start_line, loc.end_line, loc.source ? loc.source : "n/a", loc.offset);
   
   h->setKeyValue("function", str, 0);
   h->setKeyValue("line",     new QoreBigIntNode(loc.start_line), 0);
   h->setKeyValue("endline",  new QoreBigIntNode(loc.end_line), 0);
   h->setKeyValue("file",     loc.file ? new QoreStringNode(loc.file) : 0, 0);
   h->setKeyValue("source",   loc.source ? new QoreStringNode(loc.source) : 0, 0);
   h->setKeyValue("offset",   new QoreBigIntNode(loc.offset), 0);
   h->setKeyValue("typecode", new QoreBigIntNode(type), 0);
   const char *tstr = 0;
   switch (type) {
      case CT_USER:
	 tstr = "user";
         break;
      case CT_BUILTIN:
	 tstr = "builtin";
         break;
      case CT_RETHROW:
	 tstr = "rethrow";
         break;
/*
      case CT_NEWTHREAD:
	 tstr = "new-thread";
         break;
*/
      default:
	 assert(false);
   }
   h->setKeyValue("type",  new QoreStringNode(tstr), 0);
   return h;
}
Пример #7
0
OCI_Object * OCI_API OCI_ElemGetObject2(OCI_Library * pOCILib, OCI_Elem *elem, ExceptionSink* xsink)
{
    boolean res = TRUE;
    OCI_Object *obj = NULL;

    OCI_CHECK_PTR(pOCILib, OCI_IPC_ELEMENT, elem, NULL);

    if (elem->typinf->cols[0].type != OCI_CDT_OBJECT) {
       QoreStringNode* desc = new QoreStringNode("cannot retrieve an object value from element '");
       if (elem->typinf->schema) {
	  desc->concat(elem->typinf->schema);
	  desc->concat('.');
       }
       desc->sprintf("%s' of type '%s'", elem->typinf->name, OCI_GetColumnTypeName(elem->typinf->cols[0].type));
       return FALSE;
    }

    if (elem->ind != OCI_IND_NULL)
    {
        if (elem->init == FALSE)
        {
            obj = OCI_ObjectInit(pOCILib, elem->con, (OCI_Object **) &elem->obj,
                                 elem->handle, 
                                 elem->typinf->cols[0].typinf,
                                 NULL, -1, TRUE, xsink);

            elem->init = (obj != NULL);
        }
        else
            obj = (OCI_Object *) elem->obj;

        res = elem->init;
    }

    OCI_RESULT(pOCILib, res);

    return obj;
}
Пример #8
0
boolean OCI_ElemSetNumberFromString(OCI_Library* pOCILib, OCI_Elem* elem, const char* str, int size, ExceptionSink* xsink) {
    boolean res = FALSE;

    OCI_CHECK_PTR(pOCILib, OCI_IPC_ELEMENT, elem, FALSE);
    if (elem->typinf->cols[0].type != OCI_CDT_NUMERIC) {
       QoreStringNode* desc = new QoreStringNode("cannot bind a numeric value to element '");
       if (elem->typinf->schema) {
	  desc->concat(elem->typinf->schema);
	  desc->concat('.');
       }
       desc->sprintf("%s' of type '%s'", elem->typinf->name, OCI_GetColumnTypeName(elem->typinf->cols[0].type));
       return FALSE;
    }

    res = OCI_NumberConvertStr2(pOCILib, elem->con, (OCINumber*)elem->handle, str, size, NUM_FMT, NUM_FMT_LEN, xsink);

    if (res)
       OCI_ElemSetNullIndicator(elem, OCI_IND_NOTNULL);

    OCI_RESULT(pOCILib, res);

    return res;
}
Пример #9
0
OCI_Timestamp * OCI_API  OCI_ElemGetTimestamp2(OCI_Library *pOCILib, OCI_Elem *elem)
{
    boolean res = TRUE;
    OCI_Timestamp *tmsp = NULL;

    OCI_CHECK_PTR(pOCILib, OCI_IPC_ELEMENT, elem, NULL);

    if (elem->typinf->cols[0].type != OCI_CDT_TIMESTAMP) {
       QoreStringNode* desc = new QoreStringNode("cannot retrieve a timestamp value for element '");
       if (elem->typinf->schema) {
	  desc->concat(elem->typinf->schema);
	  desc->concat('.');
       }
       desc->sprintf("%s' of type '%s'", elem->typinf->name, OCI_GetColumnTypeName(elem->typinf->cols[0].type));
       return FALSE;
    }

    if (elem->ind != OCI_IND_NULL)
    {
        if (elem->init == FALSE)
        {
            tmsp = OCI_TimestampInit(pOCILib, elem->con, (OCI_Timestamp **) &elem->obj, 
                                     (OCIDateTime *) elem->handle, 
                                     elem->typinf->cols[0].subtype);

            elem->init = (tmsp != NULL);
        }
        else
            tmsp = (OCI_Timestamp *) elem->obj;

        res = elem->init;
    }

    OCI_RESULT(pOCILib, res);

    return tmsp;
}
Пример #10
0
OCI_Interval * OCI_API OCI_ElemGetInterval2(OCI_Library *pOCILib, OCI_Elem *elem)
{
    boolean res = TRUE;
    OCI_Interval *itv = NULL;

    OCI_CHECK_PTR(pOCILib, OCI_IPC_ELEMENT, elem, NULL);

    if (elem->typinf->cols[0].type != OCI_CDT_INTERVAL) {
       QoreStringNode* desc = new QoreStringNode("cannot retrieve an interval value for element '");
       if (elem->typinf->schema) {
	  desc->concat(elem->typinf->schema);
	  desc->concat('.');
       }
       desc->sprintf("%s' of type '%s'", elem->typinf->name, OCI_GetColumnTypeName(elem->typinf->cols[0].type));
       return FALSE;
    }

    if (elem->ind != OCI_IND_NULL)
    {
        if (elem->init == FALSE)
        {
            itv = OCI_IntervalInit(pOCILib, elem->con, (OCI_Interval **) &elem->obj, 
                                    (OCIInterval *) elem->handle,
                                    elem->typinf->cols[0].subtype);

            elem->init = (itv != NULL);
        }
        else
            itv = (OCI_Interval *) elem->obj;

        res = elem->init;
    }

    OCI_RESULT(pOCILib, res);

    return itv;
}
Пример #11
0
OCI_Coll * OCI_API OCI_ElemGetColl2(OCI_Library *pOCILib, OCI_Elem *elem, ExceptionSink* xsink)
{
    boolean res    = TRUE;
    OCI_Coll *coll = NULL;

    OCI_CHECK_PTR(pOCILib, OCI_IPC_ELEMENT, elem, NULL);

    if (elem->typinf->cols[0].type != OCI_CDT_COLLECTION) {
       QoreStringNode* desc = new QoreStringNode("cannot retrieve a collection from element '");
       if (elem->typinf->schema) {
	  desc->concat(elem->typinf->schema);
	  desc->concat('.');
       }
       desc->sprintf("%s' of type '%s'", elem->typinf->name, OCI_GetColumnTypeName(elem->typinf->cols[0].type));
       return FALSE;
    }

    if (elem->ind != OCI_IND_NULL)
    {
        if (elem->init == FALSE)
        {
            coll = OCI_CollInit(pOCILib, elem->con, (OCI_Coll **) &elem->obj, 
                                (OCIColl *) elem->handle, 
                                elem->typinf->cols[0].typinf, xsink);

            elem->init = (coll != NULL);
        }
        else
            coll = (OCI_Coll *) elem->obj;

        res = elem->init;
    }

    OCI_RESULT(pOCILib, res);

    return coll;
}
Пример #12
0
QoreStringNode* Datasource::getConfigString() const {
   QoreStringNode* str = new QoreStringNode(priv->dsl->getName());
   str->concat(':');

   if (!priv->username.empty())
      str->concat(priv->username);
   if (!priv->password.empty())
      str->sprintf("/%s", priv->password.c_str());
   if (!priv->dbname.empty())
      str->sprintf("@%s", priv->dbname.c_str());
   if (!priv->db_encoding.empty())
      str->sprintf("(%s)", priv->db_encoding.c_str());
   if (!priv->hostname.empty())
      str->sprintf("%%%s", priv->hostname.c_str());
   if (priv->port)
      str->sprintf(":%d", priv->port);

   bool first = false;
   ReferenceHolder<QoreHashNode> opts(qore_dbi_private::get(*priv->dsl)->getOptionHash(this), 0);
   ConstHashIterator hi(*opts);
   while (hi.next()) {
      const QoreHashNode* ov = reinterpret_cast<const QoreHashNode*>(hi.getValue());
      const AbstractQoreNode* v = ov->getKeyValue("value");
      if (!v || v == &False)
	 continue;

      if (first)
	 str->concat(',');
      else {
	 str->concat('{');
	 first = true;
      }
      str->concat(hi.getKey());
      if (v == &True)
	 continue;

      QoreStringValueHelper sv(v);
      str->sprintf("=%s", sv->getBuffer());
   }
   if (first)
      str->concat('}');

   return str;
}
Пример #13
0
OCI_Date * OCI_API  OCI_ElemGetDate2(OCI_Library *pOCILib, OCI_Elem *elem)
{
    boolean res    = TRUE;
    OCI_Date *date = NULL;

    OCI_CHECK_PTR(pOCILib, OCI_IPC_ELEMENT, elem, NULL);

    if (elem->typinf->cols[0].type != OCI_CDT_DATETIME) {
       QoreStringNode* desc = new QoreStringNode("cannot retrieve a datetime value for element '");
       if (elem->typinf->schema) {
	  desc->concat(elem->typinf->schema);
	  desc->concat('.');
       }
       desc->sprintf("%s' of type '%s'", elem->typinf->name, OCI_GetColumnTypeName(elem->typinf->cols[0].type));
       return FALSE;
    }
    
    if (elem->ind != OCI_IND_NULL)
    {
        if (elem->init == FALSE)
        {
            date = OCI_DateInit2(pOCILib, elem->con, (OCI_Date **) &elem->obj, 
                                (OCIDate *) elem->handle, FALSE, FALSE);

            elem->init = (date != NULL);
        }
        else
            date = (OCI_Date *) elem->obj;

        res = elem->init;
    }

    OCI_RESULT(pOCILib, res);

    return date;
}
Пример #14
0
OCI_Lob * OCI_API OCI_ElemGetLob2(OCI_Library *pOCILib, OCI_Elem *elem, ExceptionSink* xsink)
{
    boolean res  = TRUE;
    OCI_Lob *lob = NULL;

    OCI_CHECK_PTR(pOCILib, OCI_IPC_ELEMENT, elem, NULL);
    if (elem->typinf->cols[0].type != OCI_CDT_LOB) {
       QoreStringNode* desc = new QoreStringNode("cannot retrieve a LOB value from element '");
       if (elem->typinf->schema) {
	  desc->concat(elem->typinf->schema);
	  desc->concat('.');
       }
       desc->sprintf("%s' of type '%s'", elem->typinf->name, OCI_GetColumnTypeName(elem->typinf->cols[0].type));
       return FALSE;
    }

    if (elem->ind != OCI_IND_NULL)
    {      
        if (elem->init == FALSE)
        {
            lob = OCI_LobInit(pOCILib, elem->con, (OCI_Lob **) &elem->obj, 
                              (OCILobLocator *) elem->handle,
                              elem->typinf->cols[0].subtype, xsink);

            elem->init = (lob != NULL);
        }
        else
            lob = (OCI_Lob *) elem->obj;

        res = elem->init;
    }

    OCI_RESULT(pOCILib, res);

    return lob;
}
Пример #15
0
void QoreTypeInfo::doNonStringWarning(const QoreProgramLocation& loc, const char* preface) const {
   QoreStringNode* desc = new QoreStringNode(preface);
   getThisType(*desc);
   desc->sprintf(", which cannot be converted to a string, therefore will always evaluate to an empty string at runtime");
   qore_program_private::makeParseWarning(getProgram(), loc, QP_WARN_INVALID_OPERATION, "INVALID-OPERATION", desc);
}
Пример #16
0
void QoreTypeInfo::doNonBooleanWarning(const char* preface) const {
   QoreStringNode* desc = new QoreStringNode(preface);
   getThisType(*desc);
   desc->sprintf(", which does not evaluate to a numeric or boolean type, therefore will always evaluate to False at runtime");
   qore_program_private::makeParseWarning(getProgram(), QP_WARN_INVALID_OPERATION, "INVALID-OPERATION", desc);
}
Пример #17
0
AbstractQoreNode *QoreDotEvalOperatorNode::parseInitImpl(LocalVar *oflag, int pflag, int &lvids, const QoreTypeInfo *&returnTypeInfo) {
   assert(!returnTypeInfo);
   const QoreTypeInfo* typeInfo = 0;
   left = left->parseInit(oflag, pflag, lvids, typeInfo);

   QoreClass* qc = const_cast<QoreClass*>(typeInfo->getUniqueReturnClass());

   const QoreMethod* meth = 0;

   const char* mname = m->getName();

   if (!qc) {
      // if the left side has a type and it's not an object, then we try to match pseudo-methods
      if (typeInfo->hasType()
	  && !objectTypeInfo->parseAccepts(typeInfo)) {
	 // check for pseudo-methods
	 bool possible_match;
	 meth = pseudo_classes_find_method(typeInfo, mname, qc, possible_match);

	 if (meth) {
	    m->setPseudo();
	    // save method for optimizing calls later
	    m->parseSetClassAndMethod(qc, meth);

	    // check parameters, if any
	    lvids += m->parseArgs(oflag, pflag, meth->getFunction(), returnTypeInfo);

	    return this;
	 }
	 else if (!possible_match && !hashTypeInfo->parseAccepts(typeInfo)) {
	    // issue an error if there was no match and it's not a hash
	    QoreStringNode* edesc = new QoreStringNode;
	    edesc->sprintf("no pseudo-method <%s>.%s() can be found", typeInfo->getName(), mname);
	    qore_program_private::makeParseException(getProgram(), loc, "PARSE-TYPE-ERROR", edesc);
	 }
      }

#ifdef DEBUG
      typeInfo = 0;
      AbstractQoreNode* n = m->parseInit(oflag, pflag, lvids, typeInfo);
      assert(n == m);
#else
      m->parseInit(oflag, pflag, lvids, typeInfo);
#endif
      return this;
   }

   // make sure method arguments and return types are resolved
   qore_class_private::parseInitPartial(*qc);

   if (!m)
      return this;

   bool m_priv = false;
   meth = qore_class_private::parseFindMethodTree(*qc, mname, m_priv);

   //printd(5, "QoreDotEvalOperatorNode::parseInitImpl() %s::%s() method: %p (%s) (private: %s)\n", qc->getName(), mname, meth, meth ? meth->getClassName() : "n/a", m_priv ? "true" : "false");
   // FIXME

   const QoreListNode* args = m->getArgs();
   if (!strcmp(mname, "copy")) {
      if (args && args->size())
	 parse_error(loc, "no arguments may be passed to copy methods (%d argument%s given in call to %s::copy())", args->size(), args->size() == 1 ? "" : "s", qc->getName());

      if (meth && meth->parseIsPrivate() && (!oflag || !qore_class_private::parseCheckCompatibleClass(*qc, *(getParseClass()))))
	 parse_error(loc, "illegal call to private %s::copy() method", qc->getName());

      // do not save method pointer for copy methods
      returnTypeInfo = qc->getTypeInfo();
#ifdef DEBUG
      typeInfo = 0;
      AbstractQoreNode *n = m->parseInit(oflag, pflag, lvids, typeInfo);
      assert(n == m);
#else
      m->parseInit(oflag, pflag, lvids, typeInfo);
#endif
      return this;
   }

   // if a normal method is not found, then look for a static method
   if (!meth)
      meth = qore_class_private::parseFindStaticMethodTree(*qc, mname, m_priv);

   if (!meth) {
      if (!qc->parseHasMethodGate()) {
	 // check if it could be a pseudo-method call
	 meth = pseudo_classes_find_method(NT_OBJECT, mname, qc);
	 if (meth)
	    m->setPseudo();
	 else
	    raiseNonExistentMethodCallWarning(qc, mname);
      }

      if (!meth) {
#ifdef DEBUG
         typeInfo = 0;
	 AbstractQoreNode *n = m->parseInit(oflag, pflag, lvids, typeInfo);
	 assert(n == m);
#else
	 m->parseInit(oflag, pflag, lvids, typeInfo);
#endif
	 return this;
      }
   }

   if (m_priv && !qore_class_private::parseCheckPrivateClassAccess(*qc))
      parse_error(loc, "illegal call to private method %s::%s()", qc->getName(), mname);
   else // save method for optimizing calls later
      m->parseSetClassAndMethod(qc, meth);

   // check parameters, if any
   lvids += m->parseArgs(oflag, pflag, meth->getFunction(), returnTypeInfo);

   printd(5, "QoreDotEvalOperatorNode::parseInitImpl() %s::%s() method=%p (%s::%s()) (private=%s, static=%s) rv=%s\n", qc->getName(), mname, meth, meth ? meth->getClassName() : "n/a", mname, meth && meth->parseIsPrivate() ? "true" : "false", meth->isStatic() ? "true" : "false", returnTypeInfo->getName());

   return this;
}