Example #1
0
 void ForEachIndexImpl(covering::IntervalsT const & intervals, uint32_t scale, TFn && fn) const
 {
   CheckUniqueIndexes checkUnique(m_value.GetHeader().GetFormat() >= version::Format::v5);
   for (auto const & i : intervals)
     m_index.ForEachInIntervalAndScale(
         [&](uint32_t index)
         {
           if (checkUnique(index))
             fn(index);
         },
         i.first, i.second, scale);
 }
Example #2
0
  bool DDLIndexPopulator::checkConstraints( const IdxTuple& data, const erydbSystemCatalog::ColType& ctype, int i, int column)
  {

    switch( fConstraint )
    {
      case DDL_INVALID_CONSTRAINT:
	return true;

      case DDL_UNIQUE:
      case DDL_PRIMARY_KEY:
	if ((size_t)column + 1 < fColNames.size() )
		return true;
	return checkUnique( i, ctype );

      case DDL_NOT_NULL:
	return checkNotNull( data, ctype );

      case DDL_CHECK:
	return checkCheck( data, ctype );

      default:
	return true; //?
    }

  }
Example #3
0
void ConfigTree::ignoreConfParam(const std::string &param) const
{
    checkUnique(param);
    // if not found, peek only
    bool peek_only = _tree->find(param) == _tree->not_found();
    markVisited(param, Attr::TAG, peek_only);
}
Example #4
0
void ConfigTree::ignoreConfParamAll(const std::string &param) const
{
    checkUnique(param);
    auto& ct = markVisited(param, Attr::TAG, true);

    auto p = _tree->equal_range(param);
    for (auto it = p.first; it != p.second; ++it) {
        ++ct.count;
    }
}
Example #5
0
Range<ConfigTree::SubtreeIterator>
ConfigTree::
getConfSubtreeList(std::string const& root) const
{
    checkUnique(root);
    markVisited(root, Attr::TAG, true);

    auto p = _tree->equal_range(root);

    return Range<SubtreeIterator>(
                SubtreeIterator(p.first,  root, *this),
                SubtreeIterator(p.second, root, *this));
}
Example #6
0
Range<ConfigTree::ParameterIterator>
ConfigTree::
getConfParamList(const std::string &param) const
{
    checkUnique(param);
    markVisited(param, Attr::TAG, true);

    auto p = _tree->equal_range(param);

    return Range<ParameterIterator>(
                ParameterIterator(p.first,  param, *this),
                ParameterIterator(p.second, param, *this));
}
Example #7
0
boost::optional<ConfigTree>
ConfigTree::
getConfSubtreeOptional(std::string const& root) const
{
    checkUnique(root);

    if (auto subtree = _tree->get_child_optional(root)) {
        markVisited(root, Attr::TAG, false);
        return ConfigTree(*subtree, *this, root);
    } else {
        markVisited(root, Attr::TAG, true);
        return boost::none;
    }
}
Example #8
0
/*
 * input: 
 *  Puzzle is the sudoku
 * return:
 *  1 if puzzle is unique and will add to dict
 *  0 if not
 */
int end(int puzzle[9][9])
{
    #if PARR==1
    return 1;
    #endif
    //Create bare minumum puzzle
    int* newAddon = malloc(6*sizeof(int));
    newAddon[0] = puzzle [3][0]*10000000+puzzle[4][0]*1000000+puzzle[5][0]*100000+puzzle[3][1]*10000+puzzle[4][1]*1000+puzzle[5][1]*100+ puzzle[3][2]*10+puzzle[4][2];
    newAddon[1] = puzzle [6][0]*10000000+puzzle[7][0]*1000000+puzzle[8][0]*100000+puzzle[6][1]*10000+puzzle[7][1]*1000+puzzle[8][1]*100+puzzle[6][2]*10+puzzle[7][2];
    newAddon[2] = puzzle [0][3]*10000000+puzzle[1][3]*1000000+puzzle[2][3]*100000+puzzle[0][4]*10000+puzzle[1][4]*1000+puzzle[2][4]*100+puzzle[0][5]*10+puzzle[1][5];
    newAddon[3] = puzzle [6][3]*10000000+puzzle[7][3]*1000000+puzzle[8][3]*100000+puzzle[6][4]*10000+puzzle[7][4]*1000+puzzle[8][4]*100+puzzle[6][5]*10+puzzle[7][5];
    newAddon[4] = puzzle [0][6]*10000000+puzzle[0][7]*1000000+puzzle[0][8]*100000+puzzle[1][7]*10000+puzzle[1][8]*1000+puzzle[1][9]*100+puzzle[2][7]*10+puzzle[2][8];
    newAddon[5] = puzzle [3][6]*10000000+puzzle[4][6]*1000000+puzzle[5][6]*100000+puzzle[3][7]*10000+puzzle[4][7]*1000+puzzle[5][7]*100+puzzle[3][8]*10+puzzle[4][8];


    if(checkUnique(newAddon))//If puzzle is new
    {
        nodeAdd(head,newAddon);
        return 1;
    }
    return 0;

} 
Example #9
0
int main(int argc, char **argv)
{
	sbdclnt_t *sbdclnt;
	int port;
	int clicked;
	clock_t timeout;
	aeh_t aeh;
	int ninst;
	char comments[sendcrsh_COMMENT_MAXLEN];
	int len, lensent;
	char buf[sbd_MAXLEN];
	int pos;
	unsigned long crc;
	char signature[10];
	int i = 0;

	logprint_setFile("sendcrsh.log");

	if (!checkEnvironment()) {
		DPRINT(("anet2.dll did not set our environment!\n"));
		return 1;
	}
	if (!checkUnique()) {
		DPRINT(("Another instance of sendcrsh was running!\n"));
		return 1;
	}

	if (argc <= 3) { /* Usage: sendcrsh <host> <port> <hexdata> */
		DPRINT(("sendcrsh invoked with fewer than 3 arguments\n"));
		return 1;
	}
	DPRINT(("%s %s %s %s\n", argv[0], argv[1], argv[2], argv[3]));

	port = atoi(argv[2]);
	if ((port < 1024) || (port > 65536)) {
		DPRINT(("sendcrsh invoked with invalid port %d\n", port));
		return 1;
	}

	if (NULL == hex2buf(argv[3], buf, 2)) {
		DPRINT(("hex2buf(datalen) failed\n"));
		return 1;
	}
	len = dpMAKESHORT(buf[0], buf[1]);
	if (NULL == hex2buf(argv[3] + 4, buf, len)) {
		DPRINT(("hex2buf(data) failed\n"));
		return 1;
	}
	if (argv[3][4 + 2*len] != '\0') {
		DPRINT(("data does not end at datalen:%d\n", len));
		return 1;
	}
	if (len > sbd_MAXLEN) {
		DPRINT(("datalen:%d is greater than max:%d\n", len, sbd_MAXLEN));
		return 1;
	}
	pos = getLastRecord(buf, len, &aeh, &ninst);
	if (pos == -1) {
		DPRINT(("getLastRecord failed\n"));
		return 1;
	}
	if (aeh.nstk == 0) {
		DPRINT(("exception has 0 length stack trace\n"));
	}
	crc = aeh_getSignature(&aeh);
	if (crc == 0) {
		DPRINT(("aeh_getSignature returns 0 crc, error?\n"));
	}
	aeh_signature_toString(crc, signature);

	DPRINT(("%s to %s:%d len:%d data:%s\n", argv[0], argv[1], port, len,
		argv[3] + 4));
	sendbox_create(winCmdShow, signature, sendcrsh_COMMENT_MAXLEN, 120);
	while (1) {
		clock_t now = eclock();

		clicked = sendbox_poll(comments);
		if (clicked != sendbox_CLICKED_NONE) {
			DPRINT(("t:%d, clicked:%d, breaking\n", now, clicked));
			break;
		}
		Sleep(100);
		if (!((++i)%10)) {
			DPRINT(("%dth call to sendbox_poll at t:%d\n", i, now));
		}
	}
	sendbox_destroy();

	if (clicked != sendbox_CLICKED_OK) {
		DPRINT(("User cancelled send, clicked:%d\n", clicked));
		return 0;
	}

	timeout = eclock() + 30 * ECLOCKS_PER_SEC;
	/* add the comments to the buffer */
	if (comments[0]) {
		aeh_buf_t aehbuf;
		int commentlen = strlen(comments);
		int nwritten;

		if ((len + sizeof(unsigned int /* aeh_info_t.id */) + sizeof(commentlen) + commentlen) > sbd_MAXLEN) {
			DPRINT(("no room in buf for comment\n"));
			return 1;
		}
		/* stuff the comment into the info list */
		if (aeh_RES_OK != aeh_addComment(&aeh, comments)) {
			DPRINT(("aeh_addComment failed\n"));
			return 1;
		}
		/* convert it back to a buf */
		if (aeh_RES_OK != aeh_writeOutputStream(&aeh, &aehbuf)) {
			DPRINT(("can't convert aeh back to aehbuf\n"));
			return 1;
		}
		DPRINT(("writing new record at pos:%d buf:\n", pos));
		dumpbuf(aehbuf.buf, aehbuf.buflen);
		nwritten = aehlog_writetobuf(&aehbuf, ninst, buf+pos, sbd_MAXLEN-pos);
		if (-1 == nwritten) {
			DPRINT(("can't convert aehbuf back to buf\n"));
			return 1;
		}
		len = pos + nwritten;
	}
	aeh_Destroy(&aeh);

	/* send the buffer */
	sbdclnt = sbdclnt_create(buf, len, argv[1], (unsigned short)port);
	if (sbdclnt == NULL) {
		DPRINT(("sbdclnt_create failed\n"));
		return 1;
	}
	while ((long)(eclock() - timeout) < 0) {
		lensent = sbdclnt_poll(sbdclnt);
		if (lensent != 0)
			break;
		Sleep(100);
	}
	sbdclnt_destroy(sbdclnt);
	if (lensent != len) {
		DPRINT(("send only %d of %d bytes!\n", lensent, len));
		return 1;
	}
	DPRINT(("send completed successfully\n"));
	return 0;
}
Example #10
0
/*!
 * Load column definitions data
 *
 * \return true If data has been successfully loaded
 * \return false Otherwise
 */
bool
Table::loadData()
{
    if (mIsLoaded) {
        return true;
    }

    QSqlDatabase db = QSqlDatabase::database("mainConnect");
    QSqlQuery query(db);
    QString qstr;

    /*! \todo Before creating a query we need to find out postgres version;
     *        Bersion check can help support different Postgres versions,
     *        especcialy when the system catalogs change in newer versions
     */
    Tools::Version version = Tools::version();

    /*! \todo version check */
    /*! \todo do version specific actions */

    // create query
    qstr = QString("SELECT "
                        "pga.attname, "
                        "pg_catalog.format_type(pga.atttypid, pga.atttypmod), "
                        "pga.attnotnull "
                    "FROM "
                        "pg_catalog.pg_attribute pga "
                    "WHERE "
                        "pga.attnum > 0 "
                        "AND NOT pga.attisdropped "
                        "AND pga.attrelid = ("
                        "SELECT pgc.oid FROM pg_catalog.pg_class pgc "
                        "LEFT JOIN pg_catalog.pg_namespace pgn ON pgn.oid = pgc.relnamespace "
                        "WHERE pgc.relname = '%1' and pgn.nspname = '%2'); ")
//          "AND pg_catalog.pg_table_is_visible(pgc.oid));")
        .arg(mName)
        .arg(mSchema->name());

#ifdef DEBUG_QUERY
    qDebug() << "Psql::Table::loadData> " << qstr;
#endif

    // if query execution failed
    if (!query.exec(qstr)) {
        qDebug() << query.lastError().text();
        return false;
    }

    // if query result is empty
    if (!query.first()) {
        return false;
    }

    // for each retrieved row
    do {
        /* temporary debug output */
#if DEBUG_TRACE
        qDebug() << query.value(0).toString();
        qDebug() << query.value(1).toString();
        qDebug() << query.value(2).toString();
#endif

        // create column definition
        struct ColumnDefinition cDef;

        // populate column definition
        cDef.name = query.value(0).toString();
        cDef.type = query.value(1).toString();
        cDef.isNullable = !query.value(2).toBool();
        cDef.isPrimaryKey = checkPrimaryKey(cDef.name);
        cDef.isForeignKey = checkForeignKey(cDef.name, cDef.foreignSchemaName, cDef.foreignTableName, cDef.foreignFieldNames);
        cDef.isUnique = checkUnique(cDef.name);

        /* temporary debug output */
#if DEBUG_TRACE
        qDebug() << "NAME: " << cDef.name;
        qDebug() << "isPrimaryKey: " << cDef.isPrimaryKey;
        qDebug() << "isForeignKey: " << cDef.isForeignKey;
        qDebug() << "isUnique: " << cDef.isUnique;
        qDebug() << "FKEY_SCHEMA: " << cDef.foreignSchemaName;
        qDebug() << "FKEY_TABLE: " << cDef.foreignTableName;
#endif

        // add column definition
        mColumnDefs.push_back(cDef);
    } while (query.next());

    // clear result from previous query
    query.clear();

    // try to find parents if they exist
    qstr = QString("SELECT "
//                       "childns.nspname AS child_schema, "
//                       "child.relname AS child_name, "
                       "parentns.nspname AS parent_schema, "
                       "parent.relname AS parent_name "
                   "FROM "
                       "pg_catalog.pg_inherits i, "
                       "pg_catalog.pg_class child, "
                       "pg_catalog.pg_class parent, "
                       "pg_catalog.pg_namespace childns, "
                       "pg_catalog.pg_namespace parentns "
                   "WHERE "
                       "i.inhrelid = child.oid AND "
                       "i.inhparent = parent.oid AND "
                       "childns.oid = child.relnamespace AND "
                       "parentns.oid = parent.relnamespace AND "
                       "childns.nspname = '%1' AND "
                       "child.relname = '%2' "
                   "ORDER BY i.inhseqno;")
        .arg(mSchema.name())
        .arg(mName);

#ifdef DEBUG_QUERY
    qDebug() << "Psql::Table::loadData> " << qstr;
#endif

    // if query execution failed
    if (!query.exec(qstr)) {
        qDebug() << query.lastError().text();
        return false;
    }

    // if query result is empty
    if (query.first()) {

        do {
            DbSchemaPtr schema = Common::Database::instance()->findSchema(query.value(0).toString());
            // devtime assert
            Q_ASSERT(0 != schema.get());

            DbTablePtr table = schema->findTable(query.value(1).toString());
            // devtime assert
            Q_ASSERT(0 != table.get());

            // store handle to parent table
            mParentTables.push_back(table);

            qDebug() << "Psql::Table::loadData> Parent table: " << table.name();
        } while (query.next());
    }

    return DbTable::loadData();
}