Beispiel #1
0
static PyObject* GetDataUser(Cursor* cur, Py_ssize_t iCol, int conv)
{
    // conv
    //   The index into the connection's user-defined conversions `conv_types`.

    PyObject* value = GetDataString(cur, iCol);
    if (value == 0)
        return 0;

    PyObject* result = PyObject_CallFunction(cur->cnxn->conv_funcs[conv], "(O)", value);
    Py_DECREF(value);
    return result;
}
Beispiel #2
0
static PyObject* GetDataBuffer(Cursor* cur, Py_ssize_t iCol)
{
    PyObject* str = GetDataString(cur, iCol);

    if (str == Py_None)
        return str;

    PyObject* buffer = 0;

    if (str)
    {
        buffer = PyBuffer_FromObject(str, 0, PyString_GET_SIZE(str));
        Py_DECREF(str);         // If no buffer, release it.  If buffer, the buffer owns it.
    }

    return buffer;
}
int InitializeSearchMachine(search_machine* SearchMachine, trie* Trie)
{
  SearchMachine->Trie = Trie;

  // For each keyword in the keyword tree, set out(Node-For-Keyword) = {Keyword}
  size_t TerminalCount;
  trie** Terminals = GatherTerminals(Trie, &TerminalCount);

  // Each state has an out (set of patterns recognized upon entering it
  // out :: Map StateID [String]
  SearchMachine->Out = xcalloc(GetTrieCount(), sizeof(list*));
  for (size_t TerminalIndex = 0; TerminalIndex < TerminalCount; ++TerminalIndex)
  {
    size_t DataLength;
    size_t TerminalIdentifier = Terminals[TerminalIndex]->Identifier;
    trie_unit* DataUpToNode = GetDataString(Terminals[TerminalIndex], &DataLength);
    Assert(DataUpToNode != NULL, "ISM1");
    AllocateAndInitializeListHead(&(SearchMachine->Out[TerminalIdentifier]), DataUpToNode);
  }

  SearchMachine->Fail = xcalloc(GetTrieCount(), sizeof(trie *));

  // goto :: Map (StateID, Symbol) StatePtr
  SearchMachine->Goto = xcalloc(sizeof(void *), GetTrieCount());

  // Copy over trie links into goto
  for (size_t TrieIndex = 0; TrieIndex < GetTrieCount(); TrieIndex++)
  {
    SearchMachine->Goto[TrieIndex] = xcalloc(sizeof(trie*), UNIT_CARDINALITY);
    trie* TrieToCopy = FindInTrieByIdentifier(Trie, TrieIndex);
    memcpy(SearchMachine->Goto[TrieIndex], TrieToCopy->Children, sizeof(trie*) * UNIT_CARDINALITY);
  }

  // g(ROOT, a) := ROOT forall a in SIGMA where a doesn't leave ROOT
  for (size_t AlphabetIndex = 0; AlphabetIndex < UNIT_CARDINALITY; ++AlphabetIndex)
  {
    if (Trie->Children[AlphabetIndex] == NULL)
    {
      SearchMachine->Goto[ROOT_IDENTIFIER][AlphabetIndex] = Trie;
    }
  }

  return 0;
}
Beispiel #4
0
PyObject* GetData(Cursor* cur, Py_ssize_t iCol)
{
    // Returns an object representing the value in the row/field.  If 0 is returned, an exception has already been set.
    //
    // The data is assumed to be the default C type for the column's SQL type.

    ColumnInfo* pinfo = &cur->colinfos[iCol];

    // First see if there is a user-defined conversion.

    int conv_index = GetUserConvIndex(cur, pinfo->sql_type);
    if (conv_index != -1)
        return GetDataUser(cur, iCol, conv_index);

    switch (pinfo->sql_type)
    {
    case SQL_WCHAR:
    case SQL_WVARCHAR:
    case SQL_WLONGVARCHAR:
    case SQL_CHAR:
    case SQL_VARCHAR:
    case SQL_LONGVARCHAR:
    case SQL_GUID:
    case SQL_SS_XML:
#if PY_VERSION_HEX >= 0x02060000
    case SQL_BINARY:
    case SQL_VARBINARY:
    case SQL_LONGVARBINARY:
#endif
        return GetDataString(cur, iCol);

#if PY_VERSION_HEX < 0x02060000
    case SQL_BINARY:
    case SQL_VARBINARY:
    case SQL_LONGVARBINARY:
        return GetDataBuffer(cur, iCol);
#endif

    case SQL_DECIMAL:
    case SQL_NUMERIC:
    {
        if (decimal_type == 0)
            break;

        return GetDataDecimal(cur, iCol);
    }

    case SQL_BIT:
        return GetDataBit(cur, iCol);

    case SQL_TINYINT:
    case SQL_SMALLINT:
    case SQL_INTEGER:
        return GetDataLong(cur, iCol);

    case SQL_BIGINT:
        return GetDataLongLong(cur, iCol);

    case SQL_REAL:
    case SQL_FLOAT:
    case SQL_DOUBLE:
        return GetDataDouble(cur, iCol);


    case SQL_TYPE_DATE:
    case SQL_TYPE_TIME:
    case SQL_TYPE_TIMESTAMP:
        return GetDataTimestamp(cur, iCol);

    case SQL_SS_TIME2:
        return GetSqlServerTime(cur, iCol);
    }

    return RaiseErrorV("HY106", ProgrammingError, "ODBC SQL type %d is not yet supported.  column-index=%zd  type=%d",
                       (int)pinfo->sql_type, iCol, (int)pinfo->sql_type);
}