Esempio n. 1
0
int Question2_5::run()
{
    LinkedList* list1 = new LinkedList();
    list1->insert(5);
    list1->insert(3);
    list1->insert(6);

    LinkedList* list2 = new LinkedList();
    list2->insert(2);
    list2->insert(1);
    list2->insert(6);

    std::cout << listValue(list1->head) << " + " << listValue(list2->head) << " = ";
    sumLinks(list1->head,list2->head);
    std::cout << listValue(list1->head) << std::endl;
    delete list1;
    delete list2;
    std::cout << std::endl;

    LinkedList* list3 = new LinkedList();
    list3->insert(7);
    list3->insert(4);
    list3->insert(2);
    list3->insert(8);
    list3->insert(9);

    LinkedList* list4 = new LinkedList();
    list4->insert(2);
    list4->insert(6);

    std::cout << listValue(list3->head) << " + " << listValue(list4->head) << " = ";
    sumLinks(list3->head,list4->head);
    std::cout << listValue(list3->head) << std::endl;
    delete list3;
    delete list4;

    LinkedList* list5 = new LinkedList();
    list5->insert(7);
    list5->insert(4);
    list5->insert(2);
    list5->insert(8);
    list5->insert(9);

    LinkedList* list6 = new LinkedList();
    list6->insert(2);
    list6->insert(6);

    std::cout << std::endl << "-- Now with lists that are originally in forward order --" << std::endl;
    list5->head = reverse(list5->head);
    list6->head = reverse(list6->head);
    std::cout << listValue(list5->head) << " + " << listValue(list6->head) << " = ";
    sumLinks(list5->head,list6->head);
    std::cout << listValue(list5->head) << std::endl;
    delete list5;
    delete list6;

    return 0;
}
Esempio n. 2
0
QVariant Attribute::value()
{
    if ( useRelationTable() ) {
        // get the value from the relation table
        QSqlQuery q;
        QString query = "SELECT " + mStringCol +" FROM " + mTable + " WHERE " + mIdCol + "=:id";
        q.prepare( query  );

        if ( listValue() ) {
            QStringList idList = mValue.toStringList();
            QStringList::Iterator it = idList.begin();
            QStringList list;
            while( it != idList.end() ) {
                q.bindValue( ":id", *it );
                q.exec();
                while ( q.next() ) {
                    QString str = q.value( 0 ).toString();
                    list.append( str );
                }
                ++it;
            }
            return QVariant( list );
        } else {
            q.bindValue( ":id", mValue.toString() );
            q.exec();
            if ( q.next() ) {
                return QVariant( q.value( 0 ) );
            }
        }
    }
    return mValue;
}
Esempio n. 3
0
void Attribute::setValue( const QVariant& var )
{
    if ( useRelationTable() ) {
        QSqlQuery q;
        QString query = "SELECT " + mIdCol +" FROM " + mTable + " WHERE " + mStringCol + "=:string";

        q.prepare( query  );

        // kDebug() << "Column: " << mIdCol << " | table " << mTable << " | string: " << mStringCol << ": " << query;

        if ( listValue() ) {
            QStringList idList;
            QStringList list = var.toStringList();
            for ( QStringList::Iterator valIt = list.begin(); valIt != list.end(); ++valIt ) {
                QString curValue = *valIt;
                // kDebug() << "Searching for " << curValue << " in relation table";
                q.bindValue( ":string", curValue );
                q.exec();
                if ( q.next() ) {
                    idList << q.value( 0 ).toString();
                }
            }
            mValue = QVariant( idList );
        } else {
            q.bindValue( ":string", var.toString() );
            q.exec();
            // kDebug() << "ERROR" << q.lastError().text();
            if ( q.next() ) {
                mValue = q.value( 0 );
            }
        }
    } else {
        mValue = var;
    }
}
Esempio n. 4
0
int
remove_gtmProxy(char *name, bool clean_opt)
{
	FILE *f;
	int idx;

	/* Check if gtm proxy exists */
	if ((idx = gtmProxyIdx(name)) < 0)
	{
		elog(ERROR, "ERROR: %s is not a gtm proxy.\n", name);
		return 1;
	}
	/* Check if it is in use */
	if (ifExists(VAR_coordMasterServers, aval(VAR_gtmProxyServers)[idx]) ||
		ifExists(VAR_coordSlaveServers, aval(VAR_gtmProxyServers)[idx]) ||
		ifExists(VAR_datanodeMasterServers, aval(VAR_gtmProxyServers)[idx]) ||
		ifExists(VAR_datanodeSlaveServers, aval(VAR_gtmProxyServers)[idx]))
	{
		elog(ERROR, "ERROR: GTM Proxy %s is in use\n", name);
		return 1;
	}
	elog(NOTICE, "NOTICE: removing gtm_proxy %s\n", name);
	/* Clean */
	if (clean_opt)
	{
		char **nodelist = NULL;

		elog(NOTICE, "NOTICE: cleaning target resources.\n");
		AddMember(nodelist, name);
		clean_gtm_proxy(nodelist);
		CleanArray(nodelist);
	}
	/* Reconfigure */
	var_assign(&aval(VAR_gtmProxyNames)[idx], Strdup("none"));
	var_assign(&aval(VAR_gtmProxyServers)[idx], Strdup("none"));
	var_assign(&aval(VAR_gtmProxyPorts)[idx], Strdup("-1"));
	var_assign(&aval(VAR_gtmProxyDirs)[idx], Strdup("none"));
	handle_no_slaves();
	makeServerList();
	/* Update configuration file and backup it */
	if ((f = fopen(pgxc_ctl_config_path, "a")) == NULL)
	{
		/* Should it be panic? */
		elog(ERROR, "ERROR: cannot open configuration file \"%s\", %s\n", pgxc_ctl_config_path, strerror(errno));
		return 1;
	}
	fprintf(f, 
			"#===================================================\n"
			"# pgxc configuration file updated due to GTM proxy addition\n"
			"#        %s\n"
			"%s=%s\n"					/* gtmProxy */
			"%s=( %s )\n"				/* gtmProxyNames */
			"%s=( %s )\n"				/* gtmProxyServers */
			"%s=( %s )\n"				/* gtmProxyPorts */
			"%s=( %s )\n"				/* gtmProxyDirs */
			"#----End of reconfiguration -------------------------\n",
			timeStampString(date, MAXTOKEN+1),
			VAR_gtmProxy, sval(VAR_gtmProxy),
			VAR_gtmProxyNames, listValue(VAR_gtmProxyNames),
			VAR_gtmProxyServers, listValue(VAR_gtmProxyServers),
			VAR_gtmProxyPorts, listValue(VAR_gtmProxyPorts),
			VAR_gtmProxyDirs, listValue(VAR_gtmProxyDirs));
	fclose(f);
	backup_configuration();
	elog(NOTICE, "Done.\n");
	return 0;
}