Exemple #1
0
void db_insert_into_table( db::CDBAdapter& db, const String& table, Hashtable<String, String>& hashObject, const char* excludes = null)
{
    String cols = "";
    String quests = "";
    Vector<String> vals;

    for ( Hashtable<String,String>::iterator it = hashObject.begin();  it != hashObject.end(); ++it )
    {
        String key = it->first;
        String val  = it->second;

        if ( excludes && key.compare(excludes) == 0 )
            continue;

        if (cols.length() > 0)
        {
            cols += ',';
            quests += ',';
        }
    
        cols += key;
        quests += '?';
        vals.addElement( val );
    }

    String query = "insert into " + table + "(" + cols + ") values (" + quests + ")";

    db.executeSQLEx(query.c_str(), vals);
}
Exemple #2
0
void Tabid::pop() {
	if (symbols->size() == 0) return;
	Hashtable *bucket = (*symbols)[0];
	Hashtable::iterator iter = bucket->begin(),
			    end  = bucket->end();
	while (iter != end)
		delete iter->second;
	bucket->clear();
	symbols->pop_back();
	delete bucket;
}
Exemple #3
0
void Tabid::pop() {
	if (symbols->size() == 0) return;
	Hashtable *bucket = symbols->back();
	Hashtable::iterator iter = bucket->begin(),
			    end  = bucket->end();
	while (iter != end) {
		delete &iter->first;
		delete iter->second;
		iter++;
	}
	bucket->clear();
	symbols->pop_back();
	delete bucket;
}
VALUE rho_ringtone_manager_get_all()
{
    LOG(INFO) + __FUNCTION__;
    
    CHoldRubyValue retval(rho_ruby_createHash());

#if _WIN32_WCE > 0x501

    Hashtable<String, String> ringtones;
    CRingtoneManager::getCRingtoneManager().getAllRingtones(ringtones);

    for (Hashtable<String, String>::iterator itr = ringtones.begin();
         itr != ringtones.end(); ++itr) {
        addStrToHash( retval, itr->first.c_str(), itr->second.c_str() );
    }
#endif
    
    return retval;
}
Exemple #5
0
/*static*/ String CJSONEntry::toJSON(const Hashtable<String,String>& hash)
{
    String resHash = "{ ";
    unsigned i = 0;
    for( rho::Hashtable<rho::String, rho::String>::const_iterator it = hash.begin(); it != hash.end(); ++it, ++i)
    {
        if (i > 0)
            resHash += ",";

        resHash += "\"";
        resHash += it->first;
        resHash += "\": ";
        resHash += CJSONEntry::quoteValue(it->second);
    }

    resHash += "}";

    return resHash;
}
Exemple #6
0
Handle_ptr hashkeysCommand( CBuiltinAdapter *adapter, Context &ctx,
                 Environment *env, std::vector<Handle_ptr> args)
{
  if (1 != args.size())
    throw ArgumentCountException( 1, __FILE__, __LINE__);

  Hashtable *hashtable = asHashtable( args[0]);
  Hashtable::iterator pos = hashtable->begin();
  if (pos != hashtable->end()) {
    Handle_ptr listHead, current;
    listHead = current = ctx.factory->makeCons( ctx.factory->makeString( (*pos).first.c_str()));
    ++pos;
    for ( ; pos!=hashtable->end(); ++pos) {
      current->setCdr( ctx.factory->makeCons( ctx.factory->makeString( (*pos).first.c_str())));
      current = current->cdr();
    }
    return listHead;
  } else
    return ctx.NIL;
}
void CDBAttrManager::loadBlobAttrs(CDBAdapter& db)
{
    loadAttrs(db, m_mapBlobAttrs, "blob_attribs");

    String strTriggerPrefix = "rhoSchemaTrigger_";
    IDBResult res = db.executeSQL( "SELECT name FROM sqlite_master WHERE type='trigger'" );
    Hashtable<String,int> mapTriggers;
    for ( ; !res.isEnd(); res.next() )
    {
        String strName = res.getStringByIdx(0);
        if ( !String_startsWith(strName, strTriggerPrefix) )
            continue;

        mapTriggers[strName.substr(strTriggerPrefix.length())] = 0;
    }

    for ( HashtablePtr< int, Hashtable<String,int>* >::iterator it = m_mapBlobAttrs.begin();  it != m_mapBlobAttrs.end(); ++it )
    {
        int nSrcID = it->first;

        IDBResult res = db.executeSQL("SELECT name FROM sources WHERE source_id=?", nSrcID);
        if ( res.isEnd() )
            continue;

        String strName = res.getStringByIdx(0);
        if ( !db.isTableExist(strName) )
            continue;

        Hashtable<String,int>& hashAttribs = *it->second;
        for ( Hashtable<String,int>::iterator itAttr = hashAttribs.begin();  itAttr != hashAttribs.end(); ++itAttr )
        {
            String strTriggerName = strName + "_" + itAttr->first;
            if ( !mapTriggers.containsKey(strTriggerName + "_delete") )
            {
                String strTrigger = String("CREATE TRIGGER ") + strTriggerPrefix + strTriggerName + "_delete BEFORE DELETE ON \"" + strName + "\" FOR EACH ROW \r\n"
                "   BEGIN \r\n"
                "       SELECT rhoOnDeleteSchemaRecord( OLD." + itAttr->first + ");\r\n"
                "   END;\r\n"
                ";";

                db.createTrigger(strTrigger);
            }else
                mapTriggers[strTriggerName + "_delete"] = 1;

            if ( !mapTriggers.containsKey(strTriggerName + "_update") )
            {
                String strTrigger = String("CREATE TRIGGER ") + strTriggerPrefix + strTriggerName + "_update BEFORE UPDATE ON \"" + strName + "\" FOR EACH ROW\r\n"
                "   BEGIN \r\n"
                "       SELECT rhoOnUpdateSchemaRecord( OLD." + itAttr->first + ", NEW." + itAttr->first + ");\r\n"
                "   END;\r\n"
                ";";

                db.createTrigger(strTrigger);
            }else
                mapTriggers[strTriggerName + "_update"] = 1;

        }
    }

    //Remove outdated triggers
    for ( Hashtable<String,int>::iterator itTriggers = mapTriggers.begin();  itTriggers != mapTriggers.end(); ++itTriggers )
    {
        if ( !itTriggers->second )
        {
            db.dropTrigger(strTriggerPrefix+itTriggers->first);
        }
    }
}