void MACrossTech::serializeToDB(DBWrapper& db, const std::string& mark) { std::stringstream tableName; tableName << std::string(m_instrumentId); tableName << "_"; tableName << StratgyType::toString(this->m_type); tableName << "_MA" << m_shortMA << "_Cross_MA" << m_longMA << "_"; tableName << mark; MACrossTech::CreateTableIfNotExists(Config::Instance()->DBName(), tableName.str()); std::stringstream sql; sql.precision(12); sql << "INSERT INTO `" << tableName.str() << "` (`"; sql << "uuid" << "`,`"; sql << "LongMA" << "`,`"; sql << "ShortMA" << "`,`"; sql << "Ticktype" << "`,`"; sql << "Time" << "`,`"; sql << "LastPrice" << "`"; sql << ") VALUES("; sql << m_id << ", "; sql << m_ma_tech.mLongMAVal << ", "; sql << m_ma_tech.mShortMAVal << ", "; sql << (int)m_ticktype << ", \""; sql << m_time << "\", "; sql << m_lastprice << ")"; //std::cerr << sql.str() << std::endl; db.ExecuteNoResult(sql.str()); }
void KData::serializeToDB(DBWrapper& db){ std::string tableName(m_InstrumentID); tableName += "_1m"; KData::CreateKDataTableIfNotExists(Config::Instance()->DBName(), tableName); std::stringstream sql; sql << "INSERT INTO `" << tableName << "` (`"; sql << "Time" << "`,`"; sql << "InstrumentID" << "`,`"; sql << "LastPrice" << "`,`"; sql << "PreSettlementPrice" << "`,`"; sql << "PreClosePrice" << "`,`"; sql << "OpenPrice" << "`,`"; sql << "HighestPrice" << "`,`"; sql << "LowestPrice" << "`,`"; sql << "Volume" << "`,`"; sql << "Turnover" << "`,`"; sql << "ClosePrice" << "`,`"; sql << "SettlementPrice" << "`,`"; sql << "UpperLimitPrice" << "`,`"; sql << "LowerLimitPrice" << "`,`"; sql << "BidPrice1" << "`,`"; sql << "BidVolume1" << "`,`"; sql << "AskPrice1" << "`,`"; sql << "AskVolume1" << "`,`"; sql << "AveragePrice" << "`,`"; sql << "uuid" << "`"; sql << ") VALUES(\""; sql << m_time << "\", \""; sql << m_InstrumentID << "\", "; sql << m_LastPrice << ", "; sql << m_PreSettlementPrice << ", "; sql << m_PreClosePrice << ", "; sql << m_OpenPrice << ", "; sql << m_HighestPrice << ", "; sql << m_LowestPrice << ", "; sql << m_volume << ", "; sql << m_Turnover << ", "; sql << m_ClosePrice << ", "; sql << m_SettlementPrice << ", "; sql << m_UpperLimitPrice << ", "; sql << m_LowerLimitPrice << ", "; sql << m_BidPrice1 << ", "; sql << m_BidVolume1 << ", "; sql << m_AskPrice1 << ", "; sql << m_AskVolume1 << ", "; sql << m_averagePrice << ", "; sql << m_timestamp << ")"; //"INSERT INTO `test` (`name`) VALUES (1234) //std::cerr << sql.str() << std::endl; db.ExecuteNoResult(sql.str()); }
int MACrossTech::CreateTableIfNotExists(const std::string& dbname, const std::string& tableName) { if (MACrossTech::IsTableCreated == true){ return 0; } else { MACrossTech::IsTableCreated = true; const char* sqltempl = "CREATE TABLE IF NOT EXISTS `%s`.`%s` (\ `id` INT NOT NULL AUTO_INCREMENT, \ `uuid` BIGINT NOT NULL, \ `LongMA` Double(20,5) NULL, \ `ShortMA` Double(20,5) NULL, \ `Ticktype` int NULL, \ `Time` VARCHAR(64) NULL, \ `LastPrice` Double NULL, \ PRIMARY KEY(`id`));"; char sqlbuf[2046]; sprintf_s(sqlbuf, sqltempl, dbname.c_str(), tableName.c_str()); DBWrapper db; return db.ExecuteNoResult(sqlbuf); } }
int KData::CreateKDataTableIfNotExists(const std::string& dbname, const std::string& tableName){ if (TableIsCreatedMap.find(dbname) != TableIsCreatedMap.end() && TableIsCreatedMap[dbname] == true){ return 0; } else { TableIsCreatedMap[dbname] = true; const char* sqltempl = "CREATE TABLE IF NOT EXISTS `%s`.`%s` (\ `id` INT NOT NULL AUTO_INCREMENT, \ `Time` VARCHAR(32) NULL, \ `uuid` BIGINT NULL, \ `InstrumentID` VARCHAR(32) NULL, \ `LastPrice` DOUBLE NULL, \ `PreSettlementPrice` DOUBLE NULL, \ `PreClosePrice` DOUBLE NULL, \ `OpenPrice` DOUBLE NULL, \ `HighestPrice` DOUBLE NULL, \ `LowestPrice` DOUBLE NULL, \ `Volume` DOUBLE NULL, \ `Turnover` DOUBLE NULL, \ `ClosePrice` DOUBLE NULL, \ `SettlementPrice` DOUBLE NULL, \ `UpperLimitPrice` DOUBLE NULL, \ `LowerLimitPrice` DOUBLE NULL, \ `BidPrice1` DOUBLE NULL, \ `BidVolume1` DOUBLE NULL, \ `AskPrice1` DOUBLE NULL, \ `AskVolume1` DOUBLE NULL, \ `AveragePrice` DOUBLE NULL, \ PRIMARY KEY(`id`));"; char sqlbuf[2046]; SPRINTF(sqlbuf, sqltempl, dbname.c_str(), tableName.c_str()); DBWrapper db; return db.ExecuteNoResult(sqlbuf); } }
void DarunGrim::ListDiffDatabase(const char *storage_filename) { DBWrapper *pStorageDB = new DBWrapper((char *)storage_filename); pStorageDB->ExecuteStatement(ReadFileInfo, NULL, "SELECT id,OriginalFilePath,ComputerName,UserName,CompanyName,FileVersion,FileDescription,InternalName,ProductName,ModifiedTime,MD5Sum From FileInfo"); }
void TickWrapper::serializeToDB(DBWrapper& db) const { // if this item is recovered from db, so that we don't need serialize it to db again. if (recoveryData) return; std::string tableName(m_MdData.InstrumentID); DBUtils::CreateTickTableIfNotExists(Config::Instance()->DBName(), tableName); std::stringstream sql; sql << "INSERT INTO `" << tableName << "` (`"; sql << "Date" << "`,`"; sql << "InstrumentID" << "`,`"; sql << "ExchangeID" << "`,`"; sql << "ExchangeInstID" << "`,`"; sql << "LastPrice" << "`,`"; sql << "PreSettlementPrice" << "`,`"; sql << "PreClosePrice" << "`,`"; sql << "PreOpenInterest" << "`,`"; sql << "OpenPrice" << "`,`"; sql << "HighestPrice" << "`,`"; sql << "LowestPrice" << "`,`"; sql << "Volume" << "`,`"; sql << "Turnover" << "`,`"; sql << "OpenInterest" << "`,`"; sql << "ClosePrice" << "`,`"; sql << "SettlementPrice" << "`,`"; sql << "UpperLimitPrice" << "`,`"; sql << "LowerLimitPrice" << "`,`"; sql << "PreDelta" << "`,`"; sql << "CurrDelta"<< "`,`"; sql << "UpdateTime"<< "`,`"; sql << "UpdateMillisec" << "`,`"; sql << "BidPrice1" << "`,`"; sql << "BidVolume1" << "`,`"; sql << "AskPrice1" << "`,`"; sql << "AskVolume1" << "`,`"; sql << "BidPrice2" << "`,`"; sql << "BidVolume2" << "`,`"; sql << "AskPrice2" << "`,`"; sql << "AskVolume2" << "`,`"; sql << "BidPrice3" << "`,`"; sql << "BidVolume3" << "`,`"; sql << "AskPrice3" << "`,`"; sql << "AskVolume3" << "`,`"; sql << "BidPrice4" << "`,`"; sql << "BidVolume4" << "`,`"; sql << "AskPrice4" << "`,`"; sql << "AskVolume4" << "`,`"; sql << "BidPrice5" << "`,`"; sql << "BidVolume5" << "`,`"; sql << "AskPrice5" << "`,`"; sql << "AskVolume5" << "`,`"; sql << "AveragePrice" << "`,`"; sql << "ActionDay" << "`,`"; sql << "uuid" << "`"; sql << ") VALUES(\""; sql << m_MdData.TradingDay << "\", \"";//m_MdData.TradingDay sql << m_MdData.InstrumentID << "\", \""; sql << m_MdData.ExchangeID << "\", \""; sql << m_MdData.ExchangeInstID << "\", "; sql << m_MdData.LastPrice << ", "; sql << m_MdData.PreSettlementPrice << ", "; sql << m_MdData.PreClosePrice << ", "; sql << m_MdData.PreOpenInterest << ", "; sql << m_MdData.OpenPrice << ", "; sql << m_MdData.HighestPrice << ", "; sql << m_MdData.LowestPrice << ", "; sql << m_MdData.Volume << ", "; sql << m_MdData.Turnover << ", "; sql << m_MdData.OpenInterest << ", "; sql << m_MdData.ClosePrice << ", "; sql << m_MdData.SettlementPrice << ", "; sql << m_MdData.UpperLimitPrice << ", "; sql << m_MdData.LowerLimitPrice << ", "; sql << m_MdData.PreDelta << ", "; sql << m_MdData.CurrDelta << ", \""; sql << m_MdData.UpdateTime << "\", "; // m_MdData.UpdateTime sql << m_MdData.UpdateMillisec << ", "; sql << m_MdData.BidPrice1 << ", "; sql << m_MdData.BidVolume1 << ", "; sql << m_MdData.AskPrice1 << ", "; sql << m_MdData.AskVolume1 << ", "; sql << m_MdData.BidPrice2 << ", "; sql << m_MdData.BidVolume2 << ", "; sql << m_MdData.AskPrice2 << ", "; sql << m_MdData.AskVolume2 << ", "; sql << m_MdData.BidPrice3 << ", "; sql << m_MdData.BidVolume3 << ", "; sql << m_MdData.AskPrice3 << ", "; sql << m_MdData.AskVolume3 << ", "; sql << m_MdData.BidPrice4 << ", "; sql << m_MdData.BidVolume4 << ", "; sql << m_MdData.AskPrice4 << ", "; sql << m_MdData.AskVolume4 << ", "; sql << m_MdData.BidPrice5 << ", "; sql << m_MdData.BidVolume5 << ", "; sql << m_MdData.AskPrice5 << ", "; sql << m_MdData.AskVolume5 << ", "; sql << m_MdData.AveragePrice << ", \""; sql << m_MdData.ActionDay << "\", "; // m_MdData.ActionDay sql << m_uuid << ")"; //"INSERT INTO `test` (`name`) VALUES (1234) //std::cerr << sql.str() << std::endl; db.ExecuteNoResult(sql.str()); }
int DBUtils::CreateTickTableIfNotExists(const std::string& dbname, const std::string& tableName){ if (DBUtils::m_dict.find(tableName) != m_dict.end()){ return 0; } else { DBUtils::m_dict[tableName] = true; const char* sqltempl = "CREATE TABLE IF NOT EXISTS `%s`.`%s` (\ `id` INT NOT NULL AUTO_INCREMENT, \ `Date` DATE NULL, \ `InstrumentID` VARCHAR(32) NULL, \ `ExchangeID` VARCHAR(16) NULL, \ `ExchangeInstID` VARCHAR(32) NULL, \ `LastPrice` DOUBLE NULL, \ `PreSettlementPrice` DOUBLE NULL, \ `PreClosePrice` DOUBLE NULL, \ `PreOpenInterest` DOUBLE NULL, \ `OpenPrice` DOUBLE NULL, \ `HighestPrice` DOUBLE NULL, \ `LowestPrice` DOUBLE NULL, \ `Volume` DOUBLE NULL, \ `Turnover` DOUBLE NULL, \ `OpenInterest` DOUBLE NULL, \ `ClosePrice` DOUBLE NULL, \ `SettlementPrice` DOUBLE NULL, \ `UpperLimitPrice` DOUBLE NULL, \ `LowerLimitPrice` DOUBLE NULL, \ `PreDelta` DOUBLE NULL, \ `CurrDelta` DOUBLE NULL, \ `UpdateTime` TIME NULL, \ `UpdateMillisec` INT NULL, \ `BidPrice1` DOUBLE NULL, \ `BidVolume1` DOUBLE NULL, \ `AskPrice1` DOUBLE NULL, \ `AskVolume1` DOUBLE NULL, \ `BidPrice2` DOUBLE NULL, \ `BidVolume2` DOUBLE NULL, \ `AskPrice2` DOUBLE NULL, \ `AskVolume2` DOUBLE NULL, \ `BidPrice3` DOUBLE NULL, \ `BidVolume3` DOUBLE NULL, \ `AskPrice3` DOUBLE NULL, \ `AskVolume3` DOUBLE NULL, \ `BidPrice4` DOUBLE NULL, \ `BidVolume4` DOUBLE NULL, \ `AskPrice4` DOUBLE NULL, \ `AskVolume4` DOUBLE NULL, \ `BidPrice5` DOUBLE NULL, \ `BidVolume5` DOUBLE NULL, \ `AskPrice5` DOUBLE NULL, \ `AskVolume5` DOUBLE NULL, \ `AveragePrice` DOUBLE NULL, \ `ActionDay` DATE NULL, \ `uuid` BIGINT NULL, \ PRIMARY KEY(`id`));"; char sqlbuf[2046]; SPRINTF(sqlbuf, sqltempl, dbname.c_str(), tableName.c_str()); DBWrapper db; return db.ExecuteNoResult(sqlbuf); } }