示例#1
0
int getLinesByStation(U16_t stationId, MYKI_CD_LinesByStation_t &linesByStation, MYKI_CD_U16Array_t &lines)
{
    int returnValue=false;
    bool isNull=false;

    LinesByStationItem cacheItem;
    if (g_linesByStationCache.getCacheValue(stationId, cacheItem, isNull))
    {
        if ( !isNull )
        {
            linesByStation = cacheItem.linesByStation;
            lines = cacheItem.lines;
        }
        returnValue = !isNull;
        CsDebug(CD_DEBUG, (CD_DEBUG, "MYKI_CD:getLinesByStation: Return Cache lines by station record found for id %d.", int(stationId)));
    }
    else
    {
        DbAccess 	*m_dbAccess;

        Rows rows;

        m_dbAccess =  getDBAccess();
        if(m_dbAccess==NULL)
            return false;
        char s_query[256];
        sprintf(s_query, "SELECT line FROM StationLineRecord WHERE station='%d' AND %s ORDER BY line ASC", int(stationId), getCurrentCDVersionWhere());

        m_dbAccess->executeSqlQuery(s_query, rows);

        Rows::const_iterator itr;

        lines.arraySize = rows.size();
        if (lines.arraySize > 0)
            lines.arrayOfU16 = (U16_t*)malloc(int(lines.arraySize) * sizeof(U16_t));
        else
            lines.arrayOfU16 = NULL;
        linesByStation.station = stationId;

        int i = 0;
        for(itr = rows.begin(); itr != rows.end(); ++itr) {
            const ColumnValue& cv = *itr;
            lines.arrayOfU16[i]=convertStringToU16(cv["line"]);
            i++;
        }

        // TEST: Print out results
        if(rows.empty())
        {
            //std::cout << "\nNo Station record found for Station id " << stationId <<".\n";
            CsDebug(CD_DEBUG, (CD_DEBUG, "MYKI_CD:getServiceProviders: No Station record found for Station id %d.", stationId));
        }
        else
        {
            returnValue = true;
            //printStationLinesMap(rows);
            //testPrintLinesByStationResult(stationId, linesByStation, lines);
        }
        cacheItem.linesByStation = linesByStation;
        cacheItem.lines = lines;
        g_linesByStationCache.addCacheValue(stationId, cacheItem, !returnValue);
    }

    return returnValue;
}
示例#2
0
文件: Products.cpp 项目: PengWEI9/Vix
int processProductsSubtableXML(pugi::xpath_node node, int recordPK, std::vector<int>& subtablePKs)
{
	DbAccess* m_dbAccess = getDBAccess();
    if(m_dbAccess==NULL)
        return 2;      
	int ret = 0;

	// Get the Attribute Element Child belonging to each Record
	bool needPrimaryKeys = false;
	if (subtablePKs.empty())
	{
		needPrimaryKeys = true;
		subtablePKs.push_back(0);
		subtablePKs.push_back(0);
	}
	int& attributePK = subtablePKs[0];
	int& defaultAttributePK = subtablePKs[1];
	if (needPrimaryKeys)
	{
		Rows rows;
		m_dbAccess->executeSqlQuery("SELECT MAX(PrimaryKey) AS PrimaryKey FROM ProductAttribute", rows);
		if (!rows.empty())
			attributePK = convertStringToU32(rows.front()["PrimaryKey"]);
		rows.clear();
		m_dbAccess->executeSqlQuery("SELECT MAX(PrimaryKey) AS PrimaryKey FROM ProductDefaultAttribute", rows);
		if (!rows.empty())
			defaultAttributePK = convertStringToU32(rows.front()["PrimaryKey"]);
	}

	for (pugi::xml_node tool = node.node().first_child(); tool; tool = tool.next_sibling())
	{
		std::string childName(tool.name());

		if (childName.compare("Attribute") == 0)
		{
			std::string s_queryAttribute = "";
			std::string s_queryColumn = "";
			std::string s_queryValue = "";

			attributePK++;
			int attributeCount = 0;
			for (pugi::xml_attribute attr = tool.first_attribute(); attr; attr = attr.next_attribute())
			{
				if(attributeCount > 0)
				{
					s_queryColumn += ",";
					s_queryValue += ",";
				}
				s_queryColumn.append("'");
				s_queryColumn += attr.name();
				s_queryColumn.append("'");
				s_queryValue += sqlify(attr.value());
				attributeCount++;
			}
			s_queryAttribute = "INSERT INTO ProductAttribute('PrimaryKey',";
			s_queryAttribute += s_queryColumn;
			s_queryAttribute += ",'FK_ProductRecord') VALUES ('";
			s_queryAttribute += static_cast<std::ostringstream*>( &(std::ostringstream() << attributePK) )->str(); // PK for Device Parameter Attribute
			s_queryAttribute += "',";
			s_queryAttribute += s_queryValue;
			s_queryAttribute += ",'";
			s_queryAttribute += static_cast<std::ostringstream*>( &(std::ostringstream() << recordPK) )->str(); // FK to Device Parameter Record
			s_queryAttribute += "'";
			s_queryAttribute += ")";

			// std::cout << "\n" << s_queryDeviceParameterAttribute;
		    if ( m_dbAccess->executeSqlInsert(s_queryAttribute) != 0 )
			{
				CsErrx("Query '%s' failed", s_queryAttribute.c_str());
				ret = 2;
			}
		}
		else if (childName.compare("DefaultAttribute") == 0)
		{
			std::string s_queryDefaultAttribute = "";
			std::string s_queryColumn = "";
			std::string s_queryValue = "";

			defaultAttributePK++;
			int attributeCount = 0;
			for (pugi::xml_attribute attr = tool.first_attribute(); attr; attr = attr.next_attribute())
			{
				if(attributeCount > 0)
				{
					s_queryColumn += ",";
					s_queryValue += ",";
				}
				s_queryColumn.append("'");
				s_queryColumn += attr.name();
				s_queryColumn.append("'");
				s_queryValue += sqlify(attr.value());
				attributeCount++;
			}
			s_queryDefaultAttribute = "INSERT INTO ProductDefaultAttribute('PrimaryKey',";
			s_queryDefaultAttribute += s_queryColumn;
			s_queryDefaultAttribute += ",'FK_ProductRecord') VALUES ('";
			s_queryDefaultAttribute += static_cast<std::ostringstream*>( &(std::ostringstream() << defaultAttributePK) )->str(); // PK for Device Parameter Attribute
			s_queryDefaultAttribute += "',";
			s_queryDefaultAttribute += s_queryValue;
			s_queryDefaultAttribute += ",'";
			s_queryDefaultAttribute += static_cast<std::ostringstream*>( &(std::ostringstream() << recordPK) )->str(); // FK to Device Parameter Record
			s_queryDefaultAttribute += "'";
			s_queryDefaultAttribute += ")";

			// std::cout << "\n" << s_queryDeviceParameterAttribute;
		    if ( m_dbAccess->executeSqlInsert(s_queryDefaultAttribute) != 0 )
			{
				CsErrx("Query '%s' failed", s_queryDefaultAttribute.c_str());
				ret = 2;
			}
		}
	}

	return ret;
}
示例#3
0
int  getStationsByLine(U16_t lineId, MYKI_CD_StationsByLine_t &stationsByLine, MYKI_CD_U16Array_t &stations)
{
    int returnValue=false;
    bool isNull=false;

    StationsByLineItem cacheItem;
    if (g_stationsByLineCache.getCacheValue(lineId, cacheItem, isNull))
    {
        if (!isNull)
        {
            stationsByLine = cacheItem.stationsByLine;
            stations = cacheItem.stations;
        }
        returnValue = !isNull;
        CsDebug(CD_DEBUG, (CD_DEBUG, "MYKI_CD:getStationsByLine: Return Cache stations by line record found for id %d.", int(lineId)));
    }
    else
    {
        DbAccess 	*m_dbAccess=NULL;

        Rows rows;

        m_dbAccess =  getDBAccess();
        if(m_dbAccess==NULL)
            return false;
        char s_query[256];
        sprintf(s_query, "SELECT station FROM StationLineRecord WHERE line='%d' AND %s ORDER BY station DESC", int(lineId), getCurrentCDVersionWhere());

        m_dbAccess->executeSqlQuery(s_query, rows);

        Rows::const_iterator itr;

        stations.arraySize = rows.size();
        if (stations.arraySize > 0)
            stations.arrayOfU16 = (U16_t*)malloc(int(stations.arraySize) * sizeof(U16_t));
        else
            stations.arrayOfU16 = NULL;
        stationsByLine.line = lineId;

        int i = 0;
        for(itr = rows.begin(); itr != rows.end(); ++itr) {
            const ColumnValue& cv = *itr;
            stations.arrayOfU16[i]=convertStringToU16(cv["station"]);
            i++;
        }

        // TEST: Print out results
        if(rows.empty())
        {
            //std::cout << "\nNo Line record found for Line id " << lineId <<".\n";
            CsDebug(CD_DEBUG, (CD_DEBUG, "MYKI_CD:getStationsByLine: No Line record found for Line id %d.", lineId));
        }
        else
        {
            returnValue=true;
            //printStationLinesMap(rows);
            //testPrintStationsByLineResult(lineId, stationsByLine, stations);
        }
        cacheItem.stationsByLine = stationsByLine;
        cacheItem.stations = stations;
        g_stationsByLineCache.addCacheValue(lineId, cacheItem, !returnValue);
    }

    return returnValue;
}
示例#4
0
文件: Products.cpp 项目: PengWEI9/Vix
int getProduct(U8_t id, MYKI_CD_Product_t &product)
{
    int returnValue=false;
	DbAccess 	*m_dbAccess;
	Rows rows;
    
    CsDebug(CD_DEBUG, (CD_DEBUG, "MYKI_CD:getProduct %d", id));

	bool isNull = false;
    if(g_productCache.getCacheValue(id, product, isNull))
    {
        returnValue = !isNull;
		CsDebug(CD_DEBUG, (CD_DEBUG, "MYKI_CD:getProduct: Return Cache Product record found for id %d.", int(id)));
    }
	else
    {    
        m_dbAccess =  getDBAccess();
        if(m_dbAccess==NULL)
            return false;  
        char s_query[200];
        sprintf(s_query, "SELECT * FROM ProductRecord WHERE id='%d' AND %s", int(id), getCurrentCDVersionWhere());

        m_dbAccess->executeSqlQuery(s_query, rows);

        Rows::const_iterator itr1;
        for(itr1 = rows.begin(); itr1 != rows.end(); ++itr1){
            const ColumnValue& cv = *itr1;
            product.issuer_id = convertStringToU8(cv["issuer_id"]);
            product.id = convertStringToU8(cv["id"]);
            stringCopy(product.type, cv["type"], LEN_20_t);
            stringCopy(product.subtype, cv["subtype"], LEN_20_t);
            stringCopy(product.short_desc, cv["short_desc"], LEN_Short_Description_t);
            stringCopy(product.long_desc, cv["long_desc"], LEN_Long_Description_t);
        }



        // TEST: Print out results
        if(rows.empty())
        {
            //std::cout << "\nNo Product record found for id " << (int)id <<".\n";
            CsDebug(CD_DEBUG, (CD_DEBUG, "MYKI_CD:getProduct %d - no product exists", id));
        }
        else
        {
            CsDebug(CD_DEBUG, (CD_DEBUG, "MYKI_CD:getProduct %d - Get Attributes", id));
            // Get the product default attributes             // Get the product attributes
/*            if(getProductDefaultAttribute(id, product) && getProductAttribute(id, product))
            {
                CsDebug(CD_DEBUG, (CD_DEBUG, "MYKI_CD:getProduct %d - Return true", id));
                returnValue = true;
                //printProductMap(rows);
                //testPrintProductResult(id, product);
            }*/
            returnValue = true;
        }
        g_productCache.addCacheValue(id, product, !returnValue);
    }
    
    return returnValue;
}