Anaerin

MySQL XBMC4XBOX integration, Attempt 3

Oct 23rd, 2011
567
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 200.07 KB | None | 0 0
  1. Index: guilib/guilib.vcproj
  2. ===================================================================
  3. --- guilib/guilib.vcproj    (revision 30970)
  4. +++ guilib/guilib.vcproj    (working copy)
  5. @@ -22,7 +22,7 @@
  6.                 AdditionalOptions="/EHa"
  7.                 Optimization="0"
  8.                 OptimizeForProcessor="2"
  9. -               AdditionalIncludeDirectories="../xbmc;freetype2\include;"$(XDK)\Samples\Xbox\Common\Include";../xbmc/lib/boost"
  10. +               AdditionalIncludeDirectories=""C:\Program Files\MySQL\MySQL Connector C 6.0.2\include";../xbmc;freetype2\include;"$(XDK)\Samples\Xbox\Common\Include";../xbmc/lib/boost"
  11.                 PreprocessorDefinitions="_DEBUG;_XBOX;_LIB"
  12.                 StringPooling="FALSE"
  13.                 MinimalRebuild="FALSE"
  14. Index: xbmc.vcproj
  15. ===================================================================
  16. --- xbmc.vcproj (revision 30970)
  17. +++ xbmc.vcproj (working copy)
  18. @@ -212,11 +212,12 @@
  19.                 Name="VCCLCompilerTool"
  20.                 AdditionalOptions="/EHa"
  21.                 Optimization="1"
  22. +               GlobalOptimizations="TRUE"
  23.                 InlineFunctionExpansion="1"
  24.                 FavorSizeOrSpeed="2"
  25.                 OmitFramePointers="TRUE"
  26.                 OptimizeForProcessor="2"
  27. -               AdditionalIncludeDirectories="./xbmc;./xbmc/cores/dvdplayer/Codecs/ffmpeg;./xbmc/cores/dvdplayer/;./guilib;./guilib/common;"$(XDK)\Samples\Xbox\Common\Include";xbmc/lib/libUPnP/Platinum/Source/Devices/MediaServer;xbmc/lib/libUPnP/Platinum/Source/Devices/MediaRenderer;xbmc/lib/libUPnP/Platinum/Source/Devices/MediaConnect;xbmc/lib/libUPnP/Platinum/Source/Core;xbmc/lib/libUPnP/Platinum/Source/Platinum;xbmc/lib/libUPnP/Neptune/Source/Core;xbmc/lib/libUPnP/Neptune/Source/System/Xbox;./xbmc/lib/boost;./xbmc/lib/libRTMP;./xbmc/utils;./xbmc/xbox;./xbmc/lib/libcurl/include;./xbmc/lib;xbmc/lib/libPython/python/PC"
  28. +               AdditionalIncludeDirectories=""C:\Program Files\MySQL\MySQL Connector C 6.0.2\include";./xbmc;./xbmc/cores/dvdplayer/Codecs/ffmpeg;./xbmc/cores/dvdplayer/;./guilib;./guilib/common;"$(XDK)\Samples\Xbox\Common\Include";xbmc/lib/libUPnP/Platinum/Source/Devices/MediaServer;xbmc/lib/libUPnP/Platinum/Source/Devices/MediaRenderer;xbmc/lib/libUPnP/Platinum/Source/Devices/MediaConnect;xbmc/lib/libUPnP/Platinum/Source/Core;xbmc/lib/libUPnP/Platinum/Source/Platinum;xbmc/lib/libUPnP/Neptune/Source/Core;xbmc/lib/libUPnP/Neptune/Source/System/Xbox;./xbmc/lib/boost;./xbmc/lib/libRTMP;./xbmc/utils;./xbmc/xbox;./xbmc/lib/libcurl/include;./xbmc/lib;xbmc/lib/libPython/python/PC"
  29.                 PreprocessorDefinitions="_XBOX;_XBMC;NDEBUG;HAVE_MSWINDOWS;NOMINMAX"
  30.                 StringPooling="TRUE"
  31.                 ExceptionHandling="FALSE"
  32. @@ -233,11 +234,13 @@
  33.                 Name="VCCustomBuildTool"/>
  34.             <Tool
  35.                 Name="VCLinkerTool"
  36. -               AdditionalDependencies="xapilib.lib d3dx8.lib d3d8.lib xgraphics.lib dsound.lib xboxkrnl.lib xonline.lib xkbd.lib xvoice.lib xbdm.lib"
  37. +               AdditionalDependencies="xapilib.lib d3dx8.lib d3d8.lib xgraphics.lib dsound.lib xboxkrnl.lib xonline.lib xkbd.lib xvoice.lib xbdm.lib ws2_32.lib mysqlclient.lib"
  38. +               ShowProgress="0"
  39.                 OutputFile="$(OutDir)/$(ProjectName).exe"
  40.                 LinkIncremental="1"
  41. +               AdditionalLibraryDirectories="&quot;C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Lib&quot;;&quot;C:\Program Files\MySQL\MySQL Connector C 6.0.2\lib\opt&quot;"
  42.                 IgnoreDefaultLibraryNames="libc"
  43. -               GenerateDebugInformation="TRUE"
  44. +               GenerateDebugInformation="FALSE"
  45.                 ProgramDatabaseFile="$(OutDir)/$(ProjectName).pdb"
  46.                 SubSystem="2"
  47.                 OptimizeReferences="2"
  48. @@ -263,7 +266,8 @@
  49.                 StackSize="0x80000"
  50.                 InsertFile=".\media\dsstdfx.bin,dsstdfx,r"
  51.                 FormatUD="TRUE"
  52. -               NoPreload="LIBXBMS;LIBSMB;ISO9660;LIBHTTP;LIBMP4;LIBXDAAP;PLATINUM;LCODE"
  53. +               NoLibWarn="FALSE"
  54. +               NoPreload="LIBXBMS;LIBSMB;ISO9660;LIBHTTP;LIBMP4;LIBXDAAP;PLATINUM;LCODE;MYSQLCLIENT"
  55.                 TitleID="0xFACE008"
  56.                 MediaTypes="0x80000007"
  57.                 TitleName="XBMC"
  58. @@ -4887,6 +4891,15 @@
  59.                     RelativePath=".\xbmc\lib\sqLite\dataset.h">
  60.                 </File>
  61.                 <File
  62. +                   RelativePath=".\xbmc\lib\sqLite\DllLibMySQL.h">
  63. +               </File>
  64. +               <File
  65. +                   RelativePath=".\xbmc\lib\sqLite\mysqldataset.cpp">
  66. +               </File>
  67. +               <File
  68. +                   RelativePath=".\xbmc\lib\sqLite\mysqldataset.h">
  69. +               </File>
  70. +               <File
  71.                     RelativePath=".\xbmc\lib\sqLite\qry_dat.cpp">
  72.                 </File>
  73.                 <File
  74. @@ -4912,6 +4925,10 @@
  75.                     RelativePath=".\xbmc\lib\SlingboxLib\SlingboxLib.h">
  76.                 </File>
  77.             </Filter>
  78. +           <Filter
  79. +               Name="libmysqlclient"
  80. +               Filter="">
  81. +           </Filter>
  82.         </Filter>
  83.     </Files>
  84.     <Globals>
  85. Index: xbmc/AdvancedSettings.cpp
  86. ===================================================================
  87. --- xbmc/AdvancedSettings.cpp   (revision 30970)
  88. +++ xbmc/AdvancedSettings.cpp   (working copy)
  89. @@ -691,6 +691,29 @@
  90.  
  91.    XMLUtils::GetInt(pRootElement, "bginfoloadermaxthreads", m_bgInfoLoaderMaxThreads);
  92.    m_bgInfoLoaderMaxThreads = std::max(1, m_bgInfoLoaderMaxThreads);
  93. +
  94. +  TiXmlElement* pDatabase = pRootElement->FirstChildElement("videodatabase");
  95. +  if (pDatabase)
  96. +  {
  97. +    CLog::Log(LOGWARNING, "VIDEO database configuration is experimental.");
  98. +    XMLUtils::GetString(pDatabase, "type", m_databaseVideo.type);
  99. +    XMLUtils::GetString(pDatabase, "host", m_databaseVideo.host);
  100. +    XMLUtils::GetString(pDatabase, "port", m_databaseVideo.port);
  101. +    XMLUtils::GetString(pDatabase, "user", m_databaseVideo.user);
  102. +    XMLUtils::GetString(pDatabase, "pass", m_databaseVideo.pass);
  103. +    XMLUtils::GetString(pDatabase, "name", m_databaseVideo.name);
  104. +  }
  105. +
  106. +  pDatabase = pRootElement->FirstChildElement("musicdatabase");
  107. +  if (pDatabase)
  108. +  {
  109. +    XMLUtils::GetString(pDatabase, "type", m_databaseMusic.type);
  110. +    XMLUtils::GetString(pDatabase, "host", m_databaseMusic.host);
  111. +    XMLUtils::GetString(pDatabase, "port", m_databaseMusic.port);
  112. +    XMLUtils::GetString(pDatabase, "user", m_databaseMusic.user);
  113. +    XMLUtils::GetString(pDatabase, "pass", m_databaseMusic.pass);
  114. +    XMLUtils::GetString(pDatabase, "name", m_databaseMusic.name);
  115. +  }
  116.  
  117.    // load in the GUISettings overrides:
  118.    g_guiSettings.LoadXML(pRootElement, true);  // true to hide the settings we read in
  119. Index: xbmc/AdvancedSettings.h
  120. ===================================================================
  121. --- xbmc/AdvancedSettings.h (revision 30970)
  122. +++ xbmc/AdvancedSettings.h (working copy)
  123. @@ -25,7 +25,21 @@
  124.  #include "tinyXML/tinyxml.h"
  125.  #include "StdString.h"
  126.  #include "StringUtils.h"
  127. +// #include "Database.h"
  128.  
  129. +#ifndef DBSettingsDefined
  130. +#define DBSettingsDefined
  131. +typedef struct _DatabaseSettings
  132. +{
  133. +  CStdString type;
  134. +  CStdString host;
  135. +  CStdString port;
  136. +  CStdString user;
  137. +  CStdString pass;
  138. +  CStdString name;
  139. +} DatabaseSettings;
  140. +#endif
  141. +
  142.  struct TVShowRegexp
  143.  {
  144.    bool byDate;
  145. @@ -219,7 +233,8 @@
  146.      
  147.      bool m_bPythonVerbose;
  148.      int m_bgInfoLoaderMaxThreads;
  149. +    DatabaseSettings m_databaseMusic; // advanced music database setup
  150. +    DatabaseSettings m_databaseVideo; // advanced video database setup
  151.  };
  152.  
  153. -extern CAdvancedSettings g_advancedSettings;
  154. -
  155. +extern CAdvancedSettings g_advancedSettings;
  156. \ No newline at end of file
  157. Index: xbmc/Database.cpp
  158. ===================================================================
  159. --- xbmc/Database.cpp   (revision 30970)
  160. +++ xbmc/Database.cpp   (working copy)
  161. @@ -23,6 +23,7 @@
  162.  #include "Database.h"
  163.  #include "Util.h"
  164.  #include "Settings.h"
  165. +#include "AdvancedSettings.h"
  166.  #include "Crc32.h"
  167.  #include "FileSystem/SpecialProtocol.h"
  168.  
  169. @@ -83,24 +84,81 @@
  170.  
  171.  bool CDatabase::Open()
  172.  {
  173. +  DatabaseSettings db_fallback;
  174. +  return Open(db_fallback);
  175. +}
  176. +
  177. +bool CDatabase::Open(DatabaseSettings db)
  178. +{
  179.    if (IsOpen())
  180.    {
  181.      m_iRefCount++;
  182.      return true;
  183.    }
  184.  
  185. -  CStdString strDatabase;
  186. -  CUtil::AddFileToFolder(g_settings.GetDatabaseFolder(), m_strDatabaseFile, strDatabase);
  187. +  m_dbSettings = db;
  188.  
  189. -  m_pDB.reset(new SqliteDatabase() ) ;
  190. -  m_pDB->setDatabase(_P(strDatabase).c_str());
  191. +  bool bFallback = true;
  192. +  if ( m_dbSettings.type.Equals("mysql") )
  193. +  {
  194. +    // check we have all information before we cancel the fallback
  195. +    if ( ! (m_dbSettings.host.IsEmpty() || m_dbSettings.user.IsEmpty() || m_dbSettings.pass.IsEmpty()) )
  196. +      bFallback = false;
  197. +    else
  198. +      CLog::Log(LOGINFO, "essential mysql database information is missing (eg. host, user, pass)");
  199. +  }
  200.  
  201. +  // set default database name if appropriate
  202. +  if ( m_dbSettings.name.IsEmpty() )
  203. +    m_dbSettings.name = m_strDefaultDatabaseName;
  204. +
  205. +  // always safely fallback to sqlite3
  206. +  if (bFallback)
  207. +  {
  208. +    m_dbSettings.type = "sqlite3";
  209. +    m_dbSettings.host = _P(g_settings.GetDatabaseFolder());
  210. +  }
  211. +
  212. +  // create the appropriate database structure
  213. +  if (m_dbSettings.type.Equals("sqlite3"))
  214. +  {
  215. +    m_pDB.reset( new SqliteDatabase() ) ;
  216. +  }
  217. +  else if (m_dbSettings.type.Equals("mysql"))
  218. +  {
  219. +    m_pDB.reset( new MysqlDatabase() ) ;
  220. +  }
  221. +  else
  222. +  {
  223. +    CLog::Log(LOGERROR, "Unable to determine database type: %s", m_dbSettings.type.c_str());
  224. +    return false;
  225. +  }
  226. +
  227. +  // host name is always required
  228. +  m_pDB->setHostName(m_dbSettings.host.c_str());
  229. +
  230. +  if (!m_dbSettings.port.IsEmpty())
  231. +    m_pDB->setPort(m_dbSettings.port.c_str());
  232. +
  233. +  if (!m_dbSettings.user.IsEmpty())
  234. +    m_pDB->setLogin(m_dbSettings.user.c_str());
  235. +
  236. +  if (!m_dbSettings.pass.IsEmpty())
  237. +    m_pDB->setPasswd(m_dbSettings.pass.c_str());
  238. +
  239. +  // database name is always required
  240. +  m_pDB->setDatabase(m_dbSettings.name.c_str());
  241. +
  242. +  // create the datasets
  243.    m_pDS.reset(m_pDB->CreateDataset());
  244.    m_pDS2.reset(m_pDB->CreateDataset());
  245.  
  246. +  CLog::Log(LOGDEBUG, "CDatabase: Connecting to database %s at %s:%s",
  247. +            m_dbSettings.name.c_str(), m_dbSettings.host.c_str(), m_dbSettings.port.c_str());
  248. +
  249.    if (m_pDB->connect() != DB_CONNECTION_OK)
  250.    {
  251. -    CLog::Log(LOGERROR, "Unable to open %s (old version?)", strDatabase.c_str());
  252. +    CLog::Log(LOGERROR, "Unable to open database at host: %s db: %s (old version?)", m_dbSettings.host.c_str(), m_dbSettings.name.c_str());
  253.      return false;
  254.    }
  255.    
  256. @@ -117,33 +175,68 @@
  257.    int version = 0;
  258.    m_pDS->query("SELECT idVersion FROM version\n");
  259.    if (m_pDS->num_rows() > 0)
  260. +  {
  261. +    float fVersion = m_pDS->fv("idVersion").get_asFloat();
  262. +    if (fVersion < 2)
  263. +    { // old version - drop db completely
  264. +      CLog::Log(LOGERROR, "Unable to open %s (old version?)", m_dbSettings.name.c_str());
  265. +      Close();
  266. +      m_pDB->drop();
  267. +      return false;
  268. +    }
  269. +    else if (fVersion < 3)
  270. +   {
  271. +      // has to be old version - drop the version table
  272. +      m_pDS->close();
  273. +      CLog::Log(LOGINFO, "dropping version table");
  274. +      m_pDS->exec("drop table version");
  275. +      CLog::Log(LOGINFO, "creating version table");
  276. +      version = 3;
  277. +      m_pDS->exec("CREATE TABLE version (idVersion integer)\n");
  278. +      CStdString strSQL=FormatSQL("INSERT INTO version (idVersion) values(%i)\n", version);
  279. +      m_pDS->exec(strSQL.c_str());
  280. +   }
  281. +    else
  282.      version = m_pDS->fv("idVersion").get_asInt();
  283. -
  284. -  if (version < GetMinVersion())
  285. +  }
  286. +  CDatabase::UpdateOldVersion(version); // always call this
  287. +  if (version < m_version)
  288.    {
  289. -    CLog::Log(LOGNOTICE, "Attempting to update the database %s from version %i to %i", m_strDatabaseFile.c_str(), version, GetMinVersion());
  290. +    CLog::Log(LOGNOTICE, "Attempting to update the database %s from version %i to %i", m_dbSettings.name.c_str(), version, m_version);
  291.      if (UpdateOldVersion(version) && UpdateVersionNumber())
  292. -      CLog::Log(LOGINFO, "Update to version %i successfull", GetMinVersion());
  293. +      CLog::Log(LOGINFO, "Update to version %i successfull", m_version);
  294.      else
  295.      {
  296. -      CLog::Log(LOGERROR, "Can't update the database %s from version %i to %i", m_strDatabaseFile.c_str(), version, GetMinVersion());
  297. +      CLog::Log(LOGERROR, "Can't update the database %s from version %i to %i", m_dbSettings.name.c_str(), version, m_version);
  298.        Close();
  299.        return false;
  300.      }
  301.    }
  302. -  else if (version > GetMinVersion())
  303. +  else if (version > m_version)
  304.    {
  305. -    CLog::Log(LOGERROR, "Can't open the database %s as it is a NEWER version than what we were expecting!", m_strDatabaseFile.c_str());
  306. +    CLog::Log(LOGERROR, "Can't open the database %s as it is a NEWER version than what we were expecting!", m_dbSettings.name.c_str());
  307.      Close();
  308.      return false;
  309.    }
  310.  
  311. -  m_pDS->exec("PRAGMA cache_size=16384\n");
  312. -  m_pDS->exec("PRAGMA synchronous='NORMAL'\n");
  313. -  m_pDS->exec("PRAGMA journal_mode='TRUNCATE'\n");
  314. -//  m_pDS->exec("PRAGMA journal_mode='OFF'\n");
  315. -  m_pDS->exec("PRAGMA count_changes='OFF'\n");
  316. +  // sqlite3 post connection operations
  317. +  if (m_dbSettings.type.Equals("sqlite3"))
  318. +  {
  319. +   //  Modern file systems have a cluster/block size of 4k.
  320. +   //  To gain better performance when performing write
  321. +   //  operations to the database, set the page size of the
  322. +   //  database file to 4k.
  323. +   //  This needs to be done before any table is created.
  324. +   m_pDS->exec("PRAGMA page_size=4096\n");
  325.  
  326. +   //  Also set the memory cache size to 16k
  327. +   m_pDS->exec("PRAGMA default_cache_size=4096\n");
  328. +
  329. +   m_pDS->exec("PRAGMA cache_size=4096\n");
  330. +    m_pDS->exec("PRAGMA synchronous='NORMAL'\n");
  331. +    m_pDS->exec("PRAGMA count_changes='OFF'\n");
  332. +  }
  333. +
  334.    m_iRefCount++;
  335.    return true;
  336.  }
  337. @@ -177,7 +270,10 @@
  338.  
  339.  bool CDatabase::Compress(bool bForce /* =true */)
  340.  {
  341. -  // compress database
  342. +  // can only compress sqlite3 databases
  343. +  if (!m_dbSettings.type.Equals("sqlite3"))
  344. +    return false;
  345. +
  346.    try
  347.    {
  348.      if (NULL == m_pDB.get()) return false;
  349. @@ -203,7 +299,7 @@
  350.    }
  351.    catch (...)
  352.    {
  353. -    CLog::Log(LOGERROR, "Compressing the database %s failed", m_strDatabaseFile.c_str());
  354. +    CLog::Log(LOGERROR, "Compressing the database %s failed", m_dbSettings.name.c_str());
  355.      return false;
  356.    }
  357.    return true;
  358. @@ -263,16 +359,6 @@
  359.  
  360.  bool CDatabase::CreateTables()
  361.  {
  362. -    //  all fatx formatted partitions, except the utility drive,
  363. -    //  have a cluster size of 16k. To gain better performance
  364. -    //  when performing write operations to the database, set
  365. -    //  the page size of the database file to 16k.
  366. -    //  This needs to be done before any table is created.
  367. -    CLog::Log(LOGINFO, "Set page size");
  368. -    m_pDS->exec("PRAGMA page_size=16384\n");
  369. -    //  Also set the memory cache size to 16k
  370. -    CLog::Log(LOGINFO, "Set default cache size");
  371. -    m_pDS->exec("PRAGMA default_cache_size=16384\n");
  372.  
  373.      CLog::Log(LOGINFO, "creating version table");
  374.      m_pDS->exec("CREATE TABLE version (idVersion integer, iCompressCount integer)\n");
  375. Index: xbmc/Database.h
  376. ===================================================================
  377. --- xbmc/Database.h (revision 30970)
  378. +++ xbmc/Database.h (working copy)
  379. @@ -21,19 +21,36 @@
  380.   *
  381.   */
  382.  
  383. +#include "lib/sqLite/mysqldataset.h"
  384.  #include "lib/sqLite/sqlitedataset.h"
  385.  
  386. +#include <memory>
  387. +
  388. +#ifndef DBSettingsDefined
  389. +#define DBSettingsDefined
  390. +typedef struct _DatabaseSettings
  391. +{
  392. +  CStdString type;
  393. +  CStdString host;
  394. +  CStdString port;
  395. +  CStdString user;
  396. +  CStdString pass;
  397. +  CStdString name;
  398. +} DatabaseSettings;
  399. +#endif
  400. +
  401.  class CDatabase
  402.  {
  403.  public:
  404.    CDatabase(void);
  405.    virtual ~CDatabase(void);
  406. -  bool Open();
  407.    bool IsOpen();
  408.    void Close();
  409.    bool Compress(bool bForce=true);
  410.    void Interupt();
  411.  
  412. +  bool Open(DatabaseSettings db);
  413. +
  414.    void BeginTransaction();
  415.    virtual bool CommitTransaction();
  416.    void RollbackTransaction();
  417. @@ -43,14 +60,18 @@
  418.  protected:
  419.    void Split(const CStdString& strFileNameAndPath, CStdString& strPath, CStdString& strFileName);
  420.    DWORD ComputeCRC(const CStdString &text);
  421. -
  422. +  virtual bool Open();
  423.    virtual bool CreateTables();
  424.    virtual bool UpdateOldVersion(int version) { return true; };
  425.  
  426.    virtual int GetMinVersion() const=0;
  427.  
  428.    bool m_bOpen;
  429. -  CStdString m_strDatabaseFile;
  430. +  int m_version;
  431. +
  432. +  DatabaseSettings m_dbSettings;
  433. +  CStdString m_strDefaultDatabaseName;
  434. +
  435.    std::auto_ptr<dbiplus::Database> m_pDB;
  436.    std::auto_ptr<dbiplus::Dataset> m_pDS;
  437.    std::auto_ptr<dbiplus::Dataset> m_pDS2;
  438. Index: xbmc/lib/sqLite/dataset.cpp
  439. ===================================================================
  440. --- xbmc/lib/sqLite/dataset.cpp (revision 30970)
  441. +++ xbmc/lib/sqLite/dataset.cpp (working copy)
  442. @@ -63,9 +63,9 @@
  443.    return connect();
  444.  }
  445.  
  446. +// int Database::connect() { }
  447.  
  448.  
  449. -
  450.  //************* Dataset implementation ***************
  451.  
  452.  Dataset::Dataset() {
  453. Index: xbmc/lib/sqLite/DllLibMySQL.h
  454. ===================================================================
  455. --- xbmc/lib/sqLite/DllLibMySQL.h   (revision 0)
  456. +++ xbmc/lib/sqLite/DllLibMySQL.h   (working copy)
  457. @@ -0,0 +1,1419 @@
  458. +#pragma once
  459. +
  460. +/*
  461. + *      Copyright (C) 2011 Robert Johnston
  462. + *
  463. + *  This Program is free software; you can redistribute it and/or modify
  464. + *  it under the terms of the GNU General Public License as published by
  465. + *  the Free Software Foundation; either version 2, or (at your option)
  466. + *  any later version.
  467. + *
  468. + *  This Program is distributed in the hope that it will be useful,
  469. + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  470. + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  471. + *  GNU General Public License for more details.
  472. + *
  473. + *  You should have received a copy of the GNU General Public License
  474. + *  along with XBMC; see the file COPYING.  If not, write to
  475. + *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  476. + *  http://www.gnu.org/copyleft/gpl.html
  477. + *
  478. + *
  479. + *  Some Portions Copyright (C) 2000-2003 MySQL AB, also licensed under
  480. + *  the GPL
  481. + *
  482. + *  This file contains all the headers and function declarations
  483. + *  necessary to dynamically load libmysql.dll with XBMC's DLL loader.
  484. + */
  485. +
  486. +
  487. +
  488. +#include "DynamicDll.h"
  489. +
  490. +#ifndef _XBOX
  491. + #ifdef LoadImage
  492. +  #undef LoadImage
  493. + #endif
  494. +#endif
  495. +
  496. +/* status return codes */
  497. +#define MYSQL_NO_DATA        100
  498. +#define MYSQL_DATA_TRUNCATED 101
  499. +#define mysql_reload(mysql) mysql_refresh((mysql),REFRESH_GRANT)
  500. +#define HAVE_MYSQL_REAL_CONNECT
  501. +#define MYSQL_COUNT_ERROR (~(my_ulonglong) 0)
  502. +#define ALLOC_MAX_BLOCK_TO_DROP            4096
  503. +#define ALLOC_MAX_BLOCK_USAGE_BEFORE_DROP  10
  504. +#define ER_WARN_DATA_TRUNCATED WARN_DATA_TRUNCATED
  505. +#define mysql_library_init mysql_server_init
  506. +#define mysql_library_end mysql_server_end
  507. +#define LOCAL_INFILE_ERROR_LEN 512
  508. +//#define max_allowed_packet (*mysql_get_parameters()->p_max_allowed_packet)
  509. +//#define net_buffer_length (*mysql_get_parameters()->p_net_buffer_length)
  510. +#define PROTOCOL_VERSION       10
  511. +#define MYSQL_SERVER_VERSION       "6.0.0"
  512. +#define MYSQL_VERSION_ID       60000
  513. +#define MYSQL_PORT         3306
  514. +#define MYSQL_PORT_DEFAULT     0
  515. +#define MYSQL_UNIX_ADDR        "/tmp/mysql.sock"
  516. +#define MYSQL_CONFIG_NAME      "my"
  517. +#define MYSQL_COMPILATION_COMMENT  "Source distribution"
  518. +#define LICENSE            GPL
  519. +#define list_rest(a) ((a)->next)
  520. +#define list_push(a,b) (a)=list_cons((b),(a))
  521. +#define list_pop(A) {LIST *old=(A); (A)=list_delete(old,old) ; my_free((unsigned char *) old,MYF(MY_FAE)); }
  522. +
  523. +#define HOSTNAME_LENGTH 60
  524. +#define SYSTEM_CHARSET_MBMAXLEN 4
  525. +#define NAME_CHAR_LEN  64              /* Field/table name length */
  526. +#define USERNAME_CHAR_LENGTH 16
  527. +#define NAME_LEN                (NAME_CHAR_LEN*SYSTEM_CHARSET_MBMAXLEN)
  528. +#define USERNAME_LENGTH         (USERNAME_CHAR_LENGTH*SYSTEM_CHARSET_MBMAXLEN)
  529. +
  530. +#define SERVER_VERSION_LENGTH 60
  531. +#define SQLSTATE_LENGTH 5
  532. +
  533. +/*
  534. +  Maximum length of comments
  535. +*/
  536. +#define TABLE_COMMENT_INLINE_MAXLEN 180 /* pre 6.0: 60 (3-byte) characters */
  537. +#define TABLE_COMMENT_MAXLEN 2048
  538. +#define COLUMN_COMMENT_MAXLEN 1024
  539. +#define INDEX_COMMENT_MAXLEN 1024
  540. +
  541. +
  542. +/*
  543. +  USER_HOST_BUFF_SIZE -- length of string buffer, that is enough to contain
  544. +  username and hostname parts of the user identifier with trailing zero in
  545. +  MySQL standard format:
  546. +  user_name_part@host_name_part\0
  547. +*/
  548. +#define USER_HOST_BUFF_SIZE HOSTNAME_LENGTH + USERNAME_LENGTH + 2
  549. +
  550. +#define LOCAL_HOST "localhost"
  551. +#define LOCAL_HOST_NAMEDPIPE "."
  552. +
  553. +
  554. +#if defined(__WIN__) && !defined( _CUSTOMCONFIG_)
  555. +#define MYSQL_NAMEDPIPE "MySQL"
  556. +#define MYSQL_SERVICENAME "MySQL"
  557. +#endif /* __WIN__ */
  558. +
  559. +#ifdef _global_h
  560. +ulong STDCALL net_field_length(uchar **packet);
  561. +my_ulonglong net_field_length_ll(uchar **packet);
  562. +uchar *net_store_length(uchar *pkg, ulonglong length);
  563. +#endif
  564. +
  565. +#define NULL_LENGTH ((unsigned long) ~0) /* For net_store_length */
  566. +#define MYSQL_STMT_HEADER       4
  567. +#define MYSQL_LONG_DATA_HEADER  6
  568. +
  569. +#define NOT_FIXED_DEC           31
  570. +
  571. +
  572. +#ifndef _global_h              /* If not standard header */
  573. +#include <sys/types.h>
  574. +typedef char my_bool;
  575. +#if (defined(_WIN32) || defined(_WIN64)) && !defined(__WIN__)
  576. +#define __WIN__
  577. +#endif
  578. +
  579. +#ifndef my_socket_defined
  580. +#ifdef __WIN__
  581. +#define my_socket SOCKET
  582. +#else
  583. +typedef int my_socket;
  584. +#endif /* __WIN__ */
  585. +#endif /* my_socket_defined */
  586. +#endif /* _global_h */
  587. +
  588. +
  589. +/*
  590. +  You should add new commands to the end of this list, otherwise old
  591. +  servers won't be able to handle them as 'unsupported'.
  592. +*/
  593. +
  594. +enum enum_server_command
  595. +{
  596. +  COM_SLEEP, COM_QUIT, COM_INIT_DB, COM_QUERY, COM_FIELD_LIST,
  597. +  COM_CREATE_DB, COM_DROP_DB, COM_REFRESH, COM_SHUTDOWN, COM_STATISTICS,
  598. +  COM_PROCESS_INFO, COM_CONNECT, COM_PROCESS_KILL, COM_DEBUG, COM_PING,
  599. +  COM_TIME, COM_DELAYED_INSERT, COM_CHANGE_USER, COM_BINLOG_DUMP,
  600. +  COM_TABLE_DUMP, COM_CONNECT_OUT, COM_REGISTER_SLAVE,
  601. +  COM_STMT_PREPARE, COM_STMT_EXECUTE, COM_STMT_SEND_LONG_DATA, COM_STMT_CLOSE,
  602. +  COM_STMT_RESET, COM_SET_OPTION, COM_STMT_FETCH, COM_DAEMON,
  603. +  /* don't forget to update const char *command_name[] in sql_parse.cc */
  604. +
  605. +  /* Must be last */
  606. +  COM_END
  607. +};
  608. +
  609. +
  610. +/*
  611. +  Length of random string sent by server on handshake; this is also length of
  612. +  obfuscated password, recieved from client
  613. +*/
  614. +#define SCRAMBLE_LENGTH 20
  615. +#define SCRAMBLE_LENGTH_323 8
  616. +/* length of password stored in the db: new passwords are preceeded with '*' */
  617. +#define SCRAMBLED_PASSWORD_CHAR_LENGTH (SCRAMBLE_LENGTH*2+1)
  618. +#define SCRAMBLED_PASSWORD_CHAR_LENGTH_323 (SCRAMBLE_LENGTH_323*2)
  619. +
  620. +
  621. +#define NOT_NULL_FLAG  1       /* Field can't be NULL */
  622. +#define PRI_KEY_FLAG   2       /* Field is part of a primary key */
  623. +#define UNIQUE_KEY_FLAG 4      /* Field is part of a unique key */
  624. +#define MULTIPLE_KEY_FLAG 8        /* Field is part of a key */
  625. +#define BLOB_FLAG  16      /* Field is a blob */
  626. +#define UNSIGNED_FLAG  32      /* Field is unsigned */
  627. +#define ZEROFILL_FLAG  64      /* Field is zerofill */
  628. +#define BINARY_FLAG    128     /* Field is binary   */
  629. +
  630. +/* The following are only sent to new clients */
  631. +#define ENUM_FLAG  256     /* field is an enum */
  632. +#define AUTO_INCREMENT_FLAG 512        /* field is a autoincrement field */
  633. +#define TIMESTAMP_FLAG 1024        /* Field is a timestamp */
  634. +#define SET_FLAG   2048        /* field is a set */
  635. +#define NO_DEFAULT_VALUE_FLAG 4096 /* Field doesn't have default value */
  636. +#define ON_UPDATE_NOW_FLAG 8192         /* Field is set to NOW on UPDATE */
  637. +#define NUM_FLAG   32768       /* Field is num (for clients) */
  638. +#define PART_KEY_FLAG  16384       /* Intern; Part of some key */
  639. +#define GROUP_FLAG 32768       /* Intern: Group field */
  640. +#define UNIQUE_FLAG    65536       /* Intern: Used by sql_yacc */
  641. +#define BINCMP_FLAG    131072      /* Intern: Used by sql_yacc */
  642. +#define GET_FIXED_FIELDS_FLAG (1 << 18) /* Used to get fields in item tree */
  643. +#define FIELD_IN_PART_FUNC_FLAG (1 << 19)/* Field part of partition func */
  644. +#define FIELD_IN_ADD_INDEX (1<< 20)    /* Intern: Field used in ADD INDEX */
  645. +#define FIELD_IS_RENAMED (1<< 21)       /* Intern: Field is being renamed */
  646. +#define FIELD_STORAGE_FLAGS 22          /* Storage type: bit 22, 23 and 24 */
  647. +#define COLUMN_FORMAT_FLAGS 25          /* Column format: bit 25, 26 and 27 */
  648. +
  649. +#define REFRESH_GRANT      1   /* Refresh grant tables */
  650. +#define REFRESH_LOG        2   /* Start on new log file */
  651. +#define REFRESH_TABLES     4   /* close all tables */
  652. +#define REFRESH_HOSTS      8   /* Flush host cache */
  653. +#define REFRESH_STATUS     16  /* Flush status variables */
  654. +#define REFRESH_THREADS        32  /* Flush thread cache */
  655. +#define REFRESH_SLAVE           64      /* Reset master info and restart slave
  656. +                      thread */
  657. +#define REFRESH_MASTER          128     /* Remove all bin logs in the index
  658. +                      and truncate the index */
  659. +
  660. +/* The following can't be set with mysql_refresh() */
  661. +#define REFRESH_READ_LOCK  16384   /* Lock tables for read */
  662. +#define REFRESH_FAST       32768   /* Intern flag */
  663. +
  664. +/* RESET (remove all queries) from query cache */
  665. +#define REFRESH_QUERY_CACHE    65536
  666. +#define REFRESH_QUERY_CACHE_FREE 0x20000L /* pack query cache */
  667. +#define REFRESH_DES_KEY_FILE   0x40000L
  668. +#define REFRESH_USER_RESOURCES 0x80000L
  669. +#define REFRESH_BACKUP_LOG  0x200000L
  670. +
  671. +#define CLIENT_LONG_PASSWORD   1   /* new more secure passwords */
  672. +#define CLIENT_FOUND_ROWS  2   /* Found instead of affected rows */
  673. +#define CLIENT_LONG_FLAG   4   /* Get all column flags */
  674. +#define CLIENT_CONNECT_WITH_DB 8   /* One can specify db on connect */
  675. +#define CLIENT_NO_SCHEMA   16  /* Don't allow database.table.column */
  676. +#define CLIENT_COMPRESS        32  /* Can use compression protocol */
  677. +#define CLIENT_ODBC        64  /* Odbc client */
  678. +#define CLIENT_LOCAL_FILES 128 /* Can use LOAD DATA LOCAL */
  679. +#define CLIENT_IGNORE_SPACE    256 /* Ignore spaces before '(' */
  680. +#define CLIENT_PROTOCOL_41 512 /* New 4.1 protocol */
  681. +#define CLIENT_INTERACTIVE 1024    /* This is an interactive client */
  682. +#define CLIENT_SSL              2048   /* Switch to SSL after handshake */
  683. +#define CLIENT_IGNORE_SIGPIPE   4096    /* IGNORE sigpipes */
  684. +#define CLIENT_TRANSACTIONS    8192    /* Client knows about transactions */
  685. +#define CLIENT_RESERVED         16384   /* Old flag for 4.1 protocol  */
  686. +#define CLIENT_SECURE_CONNECTION 32768  /* New 4.1 authentication */
  687. +#define CLIENT_MULTI_STATEMENTS (1UL << 16) /* Enable/disable multi-stmt support */
  688. +#define CLIENT_MULTI_RESULTS    (1UL << 17) /* Enable/disable multi-results */
  689. +#define CLIENT_PS_MULTI_RESULTS (1UL << 18) /* Multi-results in PS-protocol */
  690. +
  691. +#define CLIENT_SSL_VERIFY_SERVER_CERT (1UL << 30)
  692. +#define CLIENT_REMEMBER_OPTIONS (1UL << 31)
  693. +
  694. +/* Gather all possible capabilites (flags) supported by the server */
  695. +#define CLIENT_ALL_FLAGS  (CLIENT_LONG_PASSWORD | \
  696. +                           CLIENT_FOUND_ROWS | \
  697. +                           CLIENT_LONG_FLAG | \
  698. +                           CLIENT_CONNECT_WITH_DB | \
  699. +                           CLIENT_NO_SCHEMA | \
  700. +                           CLIENT_COMPRESS | \
  701. +                           CLIENT_ODBC | \
  702. +                           CLIENT_LOCAL_FILES | \
  703. +                           CLIENT_IGNORE_SPACE | \
  704. +                           CLIENT_PROTOCOL_41 | \
  705. +                           CLIENT_INTERACTIVE | \
  706. +                           CLIENT_SSL | \
  707. +                           CLIENT_IGNORE_SIGPIPE | \
  708. +                           CLIENT_TRANSACTIONS | \
  709. +                           CLIENT_RESERVED | \
  710. +                           CLIENT_SECURE_CONNECTION | \
  711. +                           CLIENT_MULTI_STATEMENTS | \
  712. +                           CLIENT_MULTI_RESULTS | \
  713. +                           CLIENT_PS_MULTI_RESULTS | \
  714. +                           CLIENT_SSL_VERIFY_SERVER_CERT | \
  715. +                           CLIENT_REMEMBER_OPTIONS)
  716. +
  717. +/*
  718. +  Switch off the flags that are optional and depending on build flags
  719. +  If any of the optional flags is supported by the build it will be switched
  720. +  on before sending to the client during the connection handshake.
  721. +*/
  722. +#define CLIENT_BASIC_FLAGS (((CLIENT_ALL_FLAGS & ~CLIENT_SSL) \
  723. +                                               & ~CLIENT_COMPRESS) \
  724. +                                               & ~CLIENT_SSL_VERIFY_SERVER_CERT)
  725. +
  726. +#define SERVER_STATUS_IN_TRANS     1   /* Transaction has started */
  727. +#define SERVER_STATUS_AUTOCOMMIT   2   /* Server in auto_commit mode */
  728. +#define SERVER_MORE_RESULTS_EXISTS 8    /* Multi query - next query exists */
  729. +#define SERVER_QUERY_NO_GOOD_INDEX_USED 16
  730. +#define SERVER_QUERY_NO_INDEX_USED      32
  731. +/**
  732. +  The server was able to fulfill the clients request and opened a
  733. +  read-only non-scrollable cursor for a query. This flag comes
  734. +  in reply to COM_STMT_EXECUTE and COM_STMT_FETCH commands.
  735. +*/
  736. +#define SERVER_STATUS_CURSOR_EXISTS 64
  737. +/**
  738. +  This flag is sent when a read-only cursor is exhausted, in reply to
  739. +  COM_STMT_FETCH command.
  740. +*/
  741. +#define SERVER_STATUS_LAST_ROW_SENT 128
  742. +#define SERVER_STATUS_DB_DROPPED        256 /* A database was dropped */
  743. +#define SERVER_STATUS_NO_BACKSLASH_ESCAPES 512
  744. +/**
  745. +  Sent to the client if after a prepared statement reprepare
  746. +  we discovered that the new statement returns a different
  747. +  number of result set columns.
  748. +*/
  749. +#define SERVER_STATUS_METADATA_CHANGED 1024
  750. +/*
  751. +  Tell clients that this query was logged to the slow query log.
  752. +  Not yet set in the server, but interface is defined for applications
  753. +  to use.  See WorkLog 4098.
  754. +*/
  755. +#define SERVER_QUERY_WAS_SLOW           2048
  756. +
  757. +/**
  758. +  To mark ResultSet containing output parameter values.
  759. +*/
  760. +#define SERVER_PS_OUT_PARAMS            4096
  761. +
  762. +/**
  763. +  Server status flags that must be cleared when starting
  764. +  execution of a new SQL statement.
  765. +  Flags from this set are only added to the
  766. +  current server status by the execution engine, but
  767. +  never removed -- the execution engine expects them
  768. +  to disappear automagically by the next command.
  769. +*/
  770. +#define SERVER_STATUS_CLEAR_SET (SERVER_QUERY_NO_GOOD_INDEX_USED| \
  771. +                                 SERVER_QUERY_NO_INDEX_USED|\
  772. +                                 SERVER_MORE_RESULTS_EXISTS|\
  773. +                                 SERVER_STATUS_METADATA_CHANGED)
  774. +
  775. +#define MYSQL_ERRMSG_SIZE  512
  776. +#define NET_READ_TIMEOUT   30      /* Timeout on read */
  777. +#define NET_WRITE_TIMEOUT  60      /* Timeout on write */
  778. +#define NET_WAIT_TIMEOUT   8*60*60     /* Wait for new query */
  779. +
  780. +#define ONLY_KILL_QUERY         1
  781. +
  782. +
  783. +struct st_vio;                 /* Only C */
  784. +typedef struct st_vio Vio;
  785. +
  786. +#define MAX_TINYINT_WIDTH       3       /* Max width for a TINY w.o. sign */
  787. +#define MAX_SMALLINT_WIDTH      5       /* Max width for a SHORT w.o. sign */
  788. +#define MAX_MEDIUMINT_WIDTH     8       /* Max width for a INT24 w.o. sign */
  789. +#define MAX_INT_WIDTH           10      /* Max width for a LONG w.o. sign */
  790. +#define MAX_BIGINT_WIDTH        20      /* Max width for a LONGLONG */
  791. +#define MAX_CHAR_WIDTH     255 /* Max length for a CHAR colum */
  792. +#define MAX_BLOB_WIDTH     16777216    /* Default width for blob */
  793. +
  794. +
  795. +typedef struct st_used_mem
  796. +{                 /* struct for once_alloc (block) */
  797. +  struct st_used_mem *next;       /* Next block in use */
  798. +  size_t left;                     /* memory left in block  */
  799. +  size_t size;                     /* size of block */
  800. +} USED_MEM;
  801. +
  802. +typedef struct st_mem_root
  803. +{
  804. +  USED_MEM *free;                  /* blocks with free memory in it */
  805. +  USED_MEM *used;                  /* blocks almost without free memory */
  806. +  USED_MEM *pre_alloc;             /* preallocated block */
  807. +  /* if block have less memory it will be put in 'used' list */
  808. +  size_t min_malloc;
  809. +  size_t block_size;               /* initial block size */
  810. +  unsigned int block_num;          /* allocated blocks counter */
  811. +  /*
  812. +     first free block in queue test counter (if it exceed
  813. +     MAX_BLOCK_USAGE_BEFORE_DROP block will be dropped in 'used' list)
  814. +  */
  815. +  unsigned int first_block_usage;
  816. +
  817. +  void (*error_handler)(void);
  818. +} MEM_ROOT;
  819. +
  820. +typedef struct st_net {
  821. +#if !defined(CHECK_EMBEDDED_DIFFERENCES) || !defined(EMBEDDED_LIBRARY)
  822. +  Vio *vio;
  823. +  unsigned char *buff,*buff_end,*write_pos,*read_pos;
  824. +  my_socket fd;                    /* For Perl DBI/dbd */
  825. +  /*
  826. +    The following variable is set if we are doing several queries in one
  827. +    command ( as in LOAD TABLE ... FROM MASTER ),
  828. +    and do not want to confuse the client with OK at the wrong time
  829. +  */
  830. +  unsigned long remain_in_buf,length, buf_length, where_b;
  831. +  unsigned long max_packet,max_packet_size;
  832. +  unsigned int pkt_nr,compress_pkt_nr;
  833. +  unsigned int write_timeout, read_timeout, retry_count;
  834. +  int fcntl;
  835. +  unsigned int *return_status;
  836. +  unsigned char reading_or_writing;
  837. +  char save_char;
  838. +  my_bool unused1; /* Please remove with the next incompatible ABI change. */
  839. +  my_bool unused2; /* Please remove with the next incompatible ABI change */
  840. +  my_bool compress;
  841. +  my_bool unused3; /* Please remove with the next incompatible ABI change. */
  842. +  /*
  843. +    Pointer to query object in query cache, do not equal NULL (0) for
  844. +    queries in cache that have not stored its results yet
  845. +  */
  846. +#endif
  847. +  /*
  848. +    Unused, please remove with the next incompatible ABI change.
  849. +  */
  850. +  unsigned char *unused;
  851. +  unsigned int last_errno;
  852. +  unsigned char error;
  853. +  my_bool unused4; /* Please remove with the next incompatible ABI change. */
  854. +  my_bool unused5; /* Please remove with the next incompatible ABI change. */
  855. +  /** Client library error message buffer. Actually belongs to struct MYSQL. */
  856. +  char last_error[MYSQL_ERRMSG_SIZE];
  857. +  /** Client library sqlstate buffer. Set along with the error message. */
  858. +  char sqlstate[SQLSTATE_LENGTH+1];
  859. +  void *extension;
  860. +} NET;
  861. +
  862. +
  863. +#define packet_error (~(unsigned long) 0)
  864. +
  865. +enum enum_field_types { MYSQL_TYPE_DECIMAL, MYSQL_TYPE_TINY,
  866. +                        MYSQL_TYPE_SHORT,  MYSQL_TYPE_LONG,
  867. +                        MYSQL_TYPE_FLOAT,  MYSQL_TYPE_DOUBLE,
  868. +                        MYSQL_TYPE_NULL,   MYSQL_TYPE_TIMESTAMP,
  869. +                        MYSQL_TYPE_LONGLONG,MYSQL_TYPE_INT24,
  870. +                        MYSQL_TYPE_DATE,   MYSQL_TYPE_TIME,
  871. +                        MYSQL_TYPE_DATETIME, MYSQL_TYPE_YEAR,
  872. +                        MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR,
  873. +                        MYSQL_TYPE_BIT,
  874. +                        MYSQL_TYPE_NEWDECIMAL=246,
  875. +                        MYSQL_TYPE_ENUM=247,
  876. +                        MYSQL_TYPE_SET=248,
  877. +                        MYSQL_TYPE_TINY_BLOB=249,
  878. +                        MYSQL_TYPE_MEDIUM_BLOB=250,
  879. +                        MYSQL_TYPE_LONG_BLOB=251,
  880. +                        MYSQL_TYPE_BLOB=252,
  881. +                        MYSQL_TYPE_VAR_STRING=253,
  882. +                        MYSQL_TYPE_STRING=254,
  883. +                        MYSQL_TYPE_GEOMETRY=255,
  884. +                        MAX_NO_FIELD_TYPES /* Should always be last */
  885. +};
  886. +
  887. +/* For backward compatibility */
  888. +#define CLIENT_MULTI_QUERIES    CLIENT_MULTI_STATEMENTS    
  889. +#define FIELD_TYPE_DECIMAL     MYSQL_TYPE_DECIMAL
  890. +#define FIELD_TYPE_NEWDECIMAL  MYSQL_TYPE_NEWDECIMAL
  891. +#define FIELD_TYPE_TINY        MYSQL_TYPE_TINY
  892. +#define FIELD_TYPE_SHORT       MYSQL_TYPE_SHORT
  893. +#define FIELD_TYPE_LONG        MYSQL_TYPE_LONG
  894. +#define FIELD_TYPE_FLOAT       MYSQL_TYPE_FLOAT
  895. +#define FIELD_TYPE_DOUBLE      MYSQL_TYPE_DOUBLE
  896. +#define FIELD_TYPE_NULL        MYSQL_TYPE_NULL
  897. +#define FIELD_TYPE_TIMESTAMP   MYSQL_TYPE_TIMESTAMP
  898. +#define FIELD_TYPE_LONGLONG    MYSQL_TYPE_LONGLONG
  899. +#define FIELD_TYPE_INT24       MYSQL_TYPE_INT24
  900. +#define FIELD_TYPE_DATE        MYSQL_TYPE_DATE
  901. +#define FIELD_TYPE_TIME        MYSQL_TYPE_TIME
  902. +#define FIELD_TYPE_DATETIME    MYSQL_TYPE_DATETIME
  903. +#define FIELD_TYPE_YEAR        MYSQL_TYPE_YEAR
  904. +#define FIELD_TYPE_NEWDATE     MYSQL_TYPE_NEWDATE
  905. +#define FIELD_TYPE_ENUM        MYSQL_TYPE_ENUM
  906. +#define FIELD_TYPE_SET         MYSQL_TYPE_SET
  907. +#define FIELD_TYPE_TINY_BLOB   MYSQL_TYPE_TINY_BLOB
  908. +#define FIELD_TYPE_MEDIUM_BLOB MYSQL_TYPE_MEDIUM_BLOB
  909. +#define FIELD_TYPE_LONG_BLOB   MYSQL_TYPE_LONG_BLOB
  910. +#define FIELD_TYPE_BLOB        MYSQL_TYPE_BLOB
  911. +#define FIELD_TYPE_VAR_STRING  MYSQL_TYPE_VAR_STRING
  912. +#define FIELD_TYPE_STRING      MYSQL_TYPE_STRING
  913. +#define FIELD_TYPE_CHAR        MYSQL_TYPE_TINY
  914. +#define FIELD_TYPE_INTERVAL    MYSQL_TYPE_ENUM
  915. +#define FIELD_TYPE_GEOMETRY    MYSQL_TYPE_GEOMETRY
  916. +#define FIELD_TYPE_BIT         MYSQL_TYPE_BIT
  917. +
  918. +
  919. +/* Shutdown/kill enums and constants */
  920. +
  921. +/* Bits for THD::killable. */
  922. +#define MYSQL_SHUTDOWN_KILLABLE_CONNECT    (unsigned char)(1 << 0)
  923. +#define MYSQL_SHUTDOWN_KILLABLE_TRANS      (unsigned char)(1 << 1)
  924. +#define MYSQL_SHUTDOWN_KILLABLE_LOCK_TABLE (unsigned char)(1 << 2)
  925. +#define MYSQL_SHUTDOWN_KILLABLE_UPDATE     (unsigned char)(1 << 3)
  926. +
  927. +enum mysql_enum_shutdown_level {
  928. +  /*
  929. +    We want levels to be in growing order of hardness (because we use number
  930. +    comparisons). Note that DEFAULT does not respect the growing property, but
  931. +    it's ok.
  932. +  */
  933. +  SHUTDOWN_DEFAULT = 0,
  934. +  /* wait for existing connections to finish */
  935. +  SHUTDOWN_WAIT_CONNECTIONS= MYSQL_SHUTDOWN_KILLABLE_CONNECT,
  936. +  /* wait for existing trans to finish */
  937. +  SHUTDOWN_WAIT_TRANSACTIONS= MYSQL_SHUTDOWN_KILLABLE_TRANS,
  938. +  /* wait for existing updates to finish (=> no partial MyISAM update) */
  939. +  SHUTDOWN_WAIT_UPDATES= MYSQL_SHUTDOWN_KILLABLE_UPDATE,
  940. +  /* flush InnoDB buffers and other storage engines' buffers*/
  941. +  SHUTDOWN_WAIT_ALL_BUFFERS= (MYSQL_SHUTDOWN_KILLABLE_UPDATE << 1),
  942. +  /* don't flush InnoDB buffers, flush other storage engines' buffers*/
  943. +  SHUTDOWN_WAIT_CRITICAL_BUFFERS= (MYSQL_SHUTDOWN_KILLABLE_UPDATE << 1) + 1,
  944. +  /* Now the 2 levels of the KILL command */
  945. +#if MYSQL_VERSION_ID >= 50000
  946. +  KILL_QUERY= 254,
  947. +#endif
  948. +  KILL_CONNECTION= 255
  949. +};
  950. +
  951. +/*
  952. +  Time declarations shared between the server and client API:
  953. +  you should not add anything to this header unless it's used
  954. +  (and hence should be visible) in mysql.h.
  955. +  If you're looking for a place to add new time-related declaration,
  956. +  it's most likely my_time.h. See also "C API Handling of Date
  957. +  and Time Values" chapter in documentation.
  958. +*/
  959. +
  960. +enum enum_mysql_timestamp_type
  961. +{
  962. +  MYSQL_TIMESTAMP_NONE= -2, MYSQL_TIMESTAMP_ERROR= -1,
  963. +  MYSQL_TIMESTAMP_DATE= 0, MYSQL_TIMESTAMP_DATETIME= 1, MYSQL_TIMESTAMP_TIME= 2
  964. +};
  965. +
  966. +
  967. +/*
  968. +  Structure which is used to represent datetime values inside MySQL.
  969. +
  970. +  We assume that values in this structure are normalized, i.e. year <= 9999,
  971. +  month <= 12, day <= 31, hour <= 23, hour <= 59, hour <= 59. Many functions
  972. +  in server such as my_system_gmt_sec() or make_time() family of functions
  973. +  rely on this (actually now usage of make_*() family relies on a bit weaker
  974. +  restriction). Also functions that produce MYSQL_TIME as result ensure this.
  975. +  There is one exception to this rule though if this structure holds time
  976. +  value (time_type == MYSQL_TIMESTAMP_TIME) days and hour member can hold
  977. +  bigger values.
  978. +*/
  979. +typedef struct st_mysql_time
  980. +{
  981. +  unsigned int  year, month, day, hour, minute, second;
  982. +  unsigned long second_part;
  983. +  my_bool       neg;
  984. +  enum enum_mysql_timestamp_type time_type;
  985. +} MYSQL_TIME;
  986. +
  987. +
  988. +enum enum_cursor_type
  989. +{
  990. +  CURSOR_TYPE_NO_CURSOR= 0,
  991. +  CURSOR_TYPE_READ_ONLY= 1,
  992. +  CURSOR_TYPE_FOR_UPDATE= 2,
  993. +  CURSOR_TYPE_SCROLLABLE= 4
  994. +};
  995. +
  996. +
  997. +/* options for mysql_set_option */
  998. +enum enum_mysql_set_option
  999. +{
  1000. +  MYSQL_OPTION_MULTI_STATEMENTS_ON,
  1001. +  MYSQL_OPTION_MULTI_STATEMENTS_OFF
  1002. +};
  1003. +
  1004. +#define net_new_transaction(net) ((net)->pkt_nr=0)
  1005. +
  1006. +#ifdef __cplusplus
  1007. +extern "C" {
  1008. +#endif
  1009. +
  1010. +my_bool    my_net_init(NET *net, Vio* vio);
  1011. +void   my_net_local_init(NET *net);
  1012. +void   net_end(NET *net);
  1013. +  void net_clear(NET *net, my_bool clear_buffer);
  1014. +my_bool net_realloc(NET *net, size_t length);
  1015. +my_bool    net_flush(NET *net);
  1016. +my_bool    my_net_write(NET *net,const unsigned char *packet, size_t len);
  1017. +my_bool    net_write_command(NET *net,unsigned char command,
  1018. +             const unsigned char *header, size_t head_len,
  1019. +             const unsigned char *packet, size_t len);
  1020. +int    net_real_write(NET *net,const unsigned char *packet, size_t len);
  1021. +unsigned long my_net_read(NET *net);
  1022. +
  1023. +#ifdef _global_h
  1024. +void my_net_set_write_timeout(NET *net, uint timeout);
  1025. +void my_net_set_read_timeout(NET *net, uint timeout);
  1026. +#endif
  1027. +
  1028. +struct sockaddr;
  1029. +int my_connect(my_socket s, const struct sockaddr *name, unsigned int namelen,
  1030. +          unsigned int timeout);
  1031. +struct my_rnd_struct;
  1032. +
  1033. +#ifdef __cplusplus
  1034. +}
  1035. +#endif
  1036. +
  1037. +  /* The following is for user defined functions */
  1038. +
  1039. +enum Item_result
  1040. +{
  1041. +  STRING_RESULT=0, REAL_RESULT, INT_RESULT, ROW_RESULT, DECIMAL_RESULT
  1042. +#ifdef MYSQL_SERVER
  1043. +  ,IMPOSSIBLE_RESULT  /* Yes, we know this is ugly, don't tell us */
  1044. +  ,MAX_NO_ITEM_RESULTS = IMPOSSIBLE_RESULT /* Should always be last */
  1045. +#endif
  1046. +};
  1047. +
  1048. +typedef struct st_udf_args
  1049. +{
  1050. +  unsigned int arg_count;      /* Number of arguments */
  1051. +  enum Item_result *arg_type;      /* Pointer to item_results */
  1052. +  char **args;             /* Pointer to argument */
  1053. +  unsigned long *lengths;      /* Length of string arguments */
  1054. +  char *maybe_null;            /* Set to 1 for all maybe_null args */
  1055. +  char **attributes;                    /* Pointer to attribute name */
  1056. +  unsigned long *attribute_lengths;     /* Length of attribute arguments */
  1057. +  void *extension;
  1058. +} UDF_ARGS;
  1059. +
  1060. +  /* This holds information about the result */
  1061. +
  1062. +typedef struct st_udf_init
  1063. +{
  1064. +  my_bool maybe_null;          /* 1 if function can return NULL */
  1065. +  unsigned int decimals;       /* for real functions */
  1066. +  unsigned long max_length;    /* For string functions */
  1067. +  char *ptr;                   /* free pointer for function data */
  1068. +  my_bool const_item;          /* 1 if function always returns the same value */
  1069. +  void *extension;
  1070. +} UDF_INIT;
  1071. +/*
  1072. +  TODO: add a notion for determinism of the UDF.
  1073. +  See Item_udf_func::update_used_tables ()
  1074. +*/
  1075. +
  1076. +  /* Constants when using compression */
  1077. +#define NET_HEADER_SIZE 4      /* standard header size */
  1078. +#define COMP_HEADER_SIZE 3     /* compression header extra size */
  1079. +
  1080. +  /* Prototypes to password functions */
  1081. +
  1082. +/*
  1083. +  These functions are used for authentication by client and server and
  1084. +  implemented in sql/password.c
  1085. +*/
  1086. +
  1087. +void create_random_string(char *to, unsigned int length,
  1088. +                          struct my_rnd_struct *rand_st);
  1089. +
  1090. +void hash_password(unsigned long *to, const char *password, unsigned int password_len);
  1091. +void make_scrambled_password_323(char *to, const char *password);
  1092. +void scramble_323(char *to, const char *message, const char *password);
  1093. +my_bool check_scramble_323(const char *, const char *message,
  1094. +                           unsigned long *salt);
  1095. +void get_salt_from_password_323(unsigned long *res, const char *password);
  1096. +void make_password_from_salt_323(char *to, const unsigned long *salt);
  1097. +
  1098. +void make_scrambled_password(char *to, const char *password);
  1099. +void scramble(char *to, const char *message, const char *password);
  1100. +my_bool check_scramble(const char *reply, const char *message,
  1101. +                       const unsigned char *hash_stage2);
  1102. +void get_salt_from_password(unsigned char *res, const char *password);
  1103. +void make_password_from_salt(char *to, const unsigned char *hash_stage2);
  1104. +char *octet2hex(char *to, const char *str, unsigned int len);
  1105. +
  1106. +/* end of password.c */
  1107. +
  1108. +char *get_tty_password(const char *opt_message);
  1109. +const char *mysql_errno_to_sqlstate(unsigned int mysql_errno);
  1110. +
  1111. +/* Some other useful functions */
  1112. +
  1113. +my_bool my_thread_init(void);
  1114. +void my_thread_end(void);
  1115. +
  1116. +typedef struct st_list {
  1117. +  struct st_list *prev,*next;
  1118. +  void *data;
  1119. +} LIST;
  1120. +
  1121. +typedef int (*list_walk_action)(void *,void *);
  1122. +
  1123. +extern LIST *list_add(LIST *root,LIST *element);
  1124. +extern LIST *list_delete(LIST *root,LIST *element);
  1125. +extern LIST *list_cons(void *data,LIST *root);
  1126. +extern LIST *list_reverse(LIST *root);
  1127. +extern void list_free(LIST *root,unsigned int free_data);
  1128. +extern unsigned int list_length(LIST *);
  1129. +extern int list_walk(LIST *,list_walk_action action,unsigned char * argument);
  1130. +
  1131. +typedef struct st_mysql_field {
  1132. +  char *name;                 /* Name of column */
  1133. +  char *org_name;             /* Original column name, if an alias */
  1134. +  char *table;                /* Table of column if column was a field */
  1135. +  char *org_table;            /* Org table name, if table was an alias */
  1136. +  char *db;                   /* Database for table */
  1137. +  char *catalog;         /* Catalog for table */
  1138. +  char *def;                  /* Default value (set by mysql_list_fields) */
  1139. +  unsigned long length;       /* Width of column (create length) */
  1140. +  unsigned long max_length;   /* Max width for selected set */
  1141. +  unsigned int name_length;
  1142. +  unsigned int org_name_length;
  1143. +  unsigned int table_length;
  1144. +  unsigned int org_table_length;
  1145. +  unsigned int db_length;
  1146. +  unsigned int catalog_length;
  1147. +  unsigned int def_length;
  1148. +  unsigned int flags;         /* Div flags */
  1149. +  unsigned int decimals;      /* Number of decimals in field */
  1150. +  unsigned int charsetnr;     /* Character set */
  1151. +  enum enum_field_types type; /* Type of field. See mysql_com.h for types */
  1152. +  void *extension;
  1153. +} MYSQL_FIELD;
  1154. +
  1155. +typedef char **MYSQL_ROW;      /* return data as array of strings */
  1156. +typedef unsigned int MYSQL_FIELD_OFFSET; /* offset to current field */
  1157. +
  1158. +#ifndef _global_h
  1159. +#if defined(NO_CLIENT_LONG_LONG)
  1160. +typedef unsigned long my_ulonglong;
  1161. +#elif defined (__WIN__)
  1162. +typedef unsigned __int64 my_ulonglong;
  1163. +#else
  1164. +typedef unsigned long long my_ulonglong;
  1165. +#endif
  1166. +#endif
  1167. +
  1168. +typedef struct st_typelib {    /* Different types saved here */
  1169. +  unsigned int count;      /* How many types */
  1170. +  const char *name;        /* Name of typelib */
  1171. +  const char **type_names;
  1172. +  unsigned int *type_lengths;
  1173. +} TYPELIB;
  1174. +
  1175. +extern my_ulonglong find_typeset(char *x, TYPELIB *typelib,int *error_position);
  1176. +extern int find_type_or_exit(const char *x, TYPELIB *typelib,
  1177. +                             const char *option);
  1178. +extern int find_type(char *x, const TYPELIB *typelib, unsigned int full_name);
  1179. +extern void make_type(char *to,unsigned int nr,TYPELIB *typelib);
  1180. +extern const char *get_type(TYPELIB *typelib,unsigned int nr);
  1181. +extern TYPELIB *copy_typelib(MEM_ROOT *root, TYPELIB *from);
  1182. +
  1183. +extern TYPELIB sql_protocol_typelib;
  1184. +
  1185. +/* backward compatibility define - to be removed eventually */
  1186. +typedef struct st_mysql_rows {
  1187. +  struct st_mysql_rows *next;      /* list of rows */
  1188. +  MYSQL_ROW data;
  1189. +  unsigned long length;
  1190. +} MYSQL_ROWS;
  1191. +
  1192. +typedef MYSQL_ROWS *MYSQL_ROW_OFFSET;  /* offset to current row */
  1193. +
  1194. +typedef struct embedded_query_result EMBEDDED_QUERY_RESULT;
  1195. +typedef struct st_mysql_data {
  1196. +  MYSQL_ROWS *data;
  1197. +  struct embedded_query_result *embedded_info;
  1198. +  MEM_ROOT alloc;
  1199. +  my_ulonglong rows;
  1200. +  unsigned int fields;
  1201. +  /* extra info for embedded library */
  1202. +  void *extension;
  1203. +} MYSQL_DATA;
  1204. +
  1205. +enum mysql_option
  1206. +{
  1207. +  MYSQL_OPT_CONNECT_TIMEOUT, MYSQL_OPT_COMPRESS, MYSQL_OPT_NAMED_PIPE,
  1208. +  MYSQL_INIT_COMMAND, MYSQL_READ_DEFAULT_FILE, MYSQL_READ_DEFAULT_GROUP,
  1209. +  MYSQL_SET_CHARSET_DIR, MYSQL_SET_CHARSET_NAME, MYSQL_OPT_LOCAL_INFILE,
  1210. +  MYSQL_OPT_PROTOCOL, MYSQL_SHARED_MEMORY_BASE_NAME, MYSQL_OPT_READ_TIMEOUT,
  1211. +  MYSQL_OPT_WRITE_TIMEOUT, MYSQL_OPT_USE_RESULT,
  1212. +  MYSQL_OPT_USE_REMOTE_CONNECTION, MYSQL_OPT_USE_EMBEDDED_CONNECTION,
  1213. +  MYSQL_OPT_GUESS_CONNECTION, MYSQL_SET_CLIENT_IP, MYSQL_SECURE_AUTH,
  1214. +  MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT,
  1215. +  MYSQL_OPT_SSL_VERIFY_SERVER_CERT
  1216. +};
  1217. +
  1218. +struct st_mysql_options {
  1219. +  unsigned int connect_timeout, read_timeout, write_timeout;
  1220. +  unsigned int port, protocol;
  1221. +  unsigned long client_flag;
  1222. +  char *host,*user,*password,*unix_socket,*db;
  1223. +  struct st_dynamic_array *init_commands;
  1224. +  char *my_cnf_file,*my_cnf_group, *charset_dir, *charset_name;
  1225. +  char *ssl_key;               /* PEM key file */
  1226. +  char *ssl_cert;              /* PEM cert file */
  1227. +  char *ssl_ca;                    /* PEM CA file */
  1228. +  char *ssl_capath;                /* PEM directory of CA-s? */
  1229. +  char *ssl_cipher;                /* cipher to use */
  1230. +  char *shared_memory_base_name;
  1231. +  unsigned long max_allowed_packet;
  1232. +  my_bool use_ssl;             /* if to use SSL or not */
  1233. +  my_bool compress,named_pipe;
  1234. +  my_bool unused1;
  1235. +  my_bool unused2;
  1236. +  my_bool unused3;
  1237. +  my_bool unused4;
  1238. +  enum mysql_option methods_to_use;
  1239. +  char *client_ip;
  1240. +  /* Refuse client connecting to server if it uses old (pre-4.1.1) protocol */
  1241. +  my_bool secure_auth;
  1242. +  /* 0 - never report, 1 - always report (default) */
  1243. +  my_bool report_data_truncation;
  1244. +
  1245. +  /* function pointers for local infile support */
  1246. +  int (*local_infile_init)(void **, const char *, void *);
  1247. +  int (*local_infile_read)(void *, char *, unsigned int);
  1248. +  void (*local_infile_end)(void *);
  1249. +  int (*local_infile_error)(void *, char *, unsigned int);
  1250. +  void *local_infile_userdata;
  1251. +  void *extension;
  1252. +};
  1253. +
  1254. +enum mysql_status
  1255. +{
  1256. +  MYSQL_STATUS_READY,MYSQL_STATUS_GET_RESULT,MYSQL_STATUS_USE_RESULT
  1257. +};
  1258. +
  1259. +enum mysql_protocol_type
  1260. +{
  1261. +  MYSQL_PROTOCOL_DEFAULT, MYSQL_PROTOCOL_TCP, MYSQL_PROTOCOL_SOCKET,
  1262. +  MYSQL_PROTOCOL_PIPE, MYSQL_PROTOCOL_MEMORY
  1263. +};
  1264. +
  1265. +typedef struct character_set
  1266. +{
  1267. +  unsigned int      number;     /* character set number              */
  1268. +  unsigned int      state;      /* character set state               */
  1269. +  const char        *csname;    /* collation name                    */
  1270. +  const char        *name;      /* character set name                */
  1271. +  const char        *comment;   /* comment                           */
  1272. +  const char        *dir;       /* character set directory           */
  1273. +  unsigned int      mbminlen;   /* min. length for multibyte strings */
  1274. +  unsigned int      mbmaxlen;   /* max. length for multibyte strings */
  1275. +} MY_CHARSET_INFO;
  1276. +
  1277. +struct st_mysql_methods;
  1278. +struct st_mysql_stmt;
  1279. +
  1280. +typedef struct st_mysql
  1281. +{
  1282. +  NET      net;            /* Communication parameters */
  1283. +  unsigned char    *connector_fd;      /* ConnectorFd for SSL */
  1284. +  char     *host,*user,*passwd,*unix_socket,*server_version,*host_info;
  1285. +  char          *info, *db;
  1286. +  struct charset_info_st *charset;
  1287. +  MYSQL_FIELD  *fields;
  1288. +  MEM_ROOT field_alloc;
  1289. +  my_ulonglong affected_rows;
  1290. +  my_ulonglong insert_id;      /* id if insert on table with NEXTNR */
  1291. +  my_ulonglong extra_info;     /* Not used */
  1292. +  unsigned long thread_id;     /* Id for connection in server */
  1293. +  unsigned long packet_length;
  1294. +  unsigned int port;
  1295. +  unsigned long client_flag,server_capabilities;
  1296. +  unsigned int protocol_version;
  1297. +  unsigned int field_count;
  1298. +  unsigned int     server_status;
  1299. +  unsigned int  server_language;
  1300. +  unsigned int warning_count;
  1301. +  struct st_mysql_options options;
  1302. +  enum mysql_status status;
  1303. +  my_bool  free_me;        /* If free in mysql_close */
  1304. +  my_bool  reconnect;      /* set to 1 if automatic reconnect */
  1305. +
  1306. +  /* session-wide random string */
  1307. +  char         scramble[SCRAMBLE_LENGTH+1];
  1308. +  my_bool unused1;
  1309. +  void *unused2, *unused3, *unused4, *unused5;
  1310. +
  1311. +  LIST  *stmts;                     /* list of all statements */
  1312. +  const struct st_mysql_methods *methods;
  1313. +  void *thd;
  1314. +  /*
  1315. +    Points to boolean flag in MYSQL_RES  or MYSQL_STMT. We set this flag
  1316. +    from mysql_stmt_close if close had to cancel result set of this object.
  1317. +  */
  1318. +  my_bool *unbuffered_fetch_owner;
  1319. +  /* needed for embedded server - no net buffer to store the 'info' */
  1320. +  char *info_buffer;
  1321. +  void *extension;
  1322. +} MYSQL;
  1323. +
  1324. +
  1325. +typedef struct st_mysql_res {
  1326. +  my_ulonglong  row_count;
  1327. +  MYSQL_FIELD  *fields;
  1328. +  MYSQL_DATA   *data;
  1329. +  MYSQL_ROWS   *data_cursor;
  1330. +  unsigned long *lengths;      /* column lengths of current row */
  1331. +  MYSQL        *handle;        /* for unbuffered reads */
  1332. +  const struct st_mysql_methods *methods;
  1333. +  MYSQL_ROW    row;            /* If unbuffered read */
  1334. +  MYSQL_ROW    current_row;        /* buffer to current row */
  1335. +  MEM_ROOT field_alloc;
  1336. +  unsigned int field_count, current_field;
  1337. +  my_bool  eof;            /* Used by mysql_fetch_row */
  1338. +  /* mysql_stmt_close() had to cancel this result */
  1339. +  my_bool       unbuffered_fetch_cancelled;  
  1340. +  void *extension;
  1341. +} MYSQL_RES;
  1342. +
  1343. +
  1344. +typedef struct st_mysql_parameters
  1345. +{
  1346. +  unsigned long *p_max_allowed_packet;
  1347. +  unsigned long *p_net_buffer_length;
  1348. +  void *extension;
  1349. +} MYSQL_PARAMETERS;
  1350. +
  1351. +/*
  1352. +  The following definitions are added for the enhanced
  1353. +  client-server protocol
  1354. +*/
  1355. +
  1356. +/* statement state */
  1357. +enum enum_mysql_stmt_state
  1358. +{
  1359. +  MYSQL_STMT_INIT_DONE= 1, MYSQL_STMT_PREPARE_DONE, MYSQL_STMT_EXECUTE_DONE,
  1360. +  MYSQL_STMT_FETCH_DONE
  1361. +};
  1362. +
  1363. +/*
  1364. +  This structure is used to define bind information, and
  1365. +  internally by the client library.
  1366. +  Public members with their descriptions are listed below
  1367. +  (conventionally `On input' refers to the binds given to
  1368. +  mysql_stmt_bind_param, `On output' refers to the binds given
  1369. +  to mysql_stmt_bind_result):
  1370. +
  1371. +  buffer_type    - One of the MYSQL_* types, used to describe
  1372. +                   the host language type of buffer.
  1373. +                   On output: if column type is different from
  1374. +                   buffer_type, column value is automatically converted
  1375. +                   to buffer_type before it is stored in the buffer.
  1376. +  buffer         - On input: points to the buffer with input data.
  1377. +                   On output: points to the buffer capable to store
  1378. +                   output data.
  1379. +                   The type of memory pointed by buffer must correspond
  1380. +                   to buffer_type. See the correspondence table in
  1381. +                   the comment to mysql_stmt_bind_param.
  1382. +
  1383. +  The two above members are mandatory for any kind of bind.
  1384. +
  1385. +  buffer_length  - the length of the buffer. You don't have to set
  1386. +                   it for any fixed length buffer: float, double,
  1387. +                   int, etc. It must be set however for variable-length
  1388. +                   types, such as BLOBs or STRINGs.
  1389. +
  1390. +  length         - On input: in case when lengths of input values
  1391. +                   are different for each execute, you can set this to
  1392. +                   point at a variable containining value length. This
  1393. +                   way the value length can be different in each execute.
  1394. +                   If length is not NULL, buffer_length is not used.
  1395. +                   Note, length can even point at buffer_length if
  1396. +                   you keep bind structures around while fetching:
  1397. +                   this way you can change buffer_length before
  1398. +                   each execution, everything will work ok.
  1399. +                   On output: if length is set, mysql_stmt_fetch will
  1400. +                   write column length into it.
  1401. +
  1402. +  is_null        - On input: points to a boolean variable that should
  1403. +                   be set to TRUE for NULL values.
  1404. +                   This member is useful only if your data may be
  1405. +                   NULL in some but not all cases.
  1406. +                   If your data is never NULL, is_null should be set to 0.
  1407. +                   If your data is always NULL, set buffer_type
  1408. +                   to MYSQL_TYPE_NULL, and is_null will not be used.
  1409. +
  1410. +  is_unsigned    - On input: used to signify that values provided for one
  1411. +                   of numeric types are unsigned.
  1412. +                   On output describes signedness of the output buffer.
  1413. +                   If, taking into account is_unsigned flag, column data
  1414. +                   is out of range of the output buffer, data for this column
  1415. +                   is regarded truncated. Note that this has no correspondence
  1416. +                   to the sign of result set column, if you need to find it out
  1417. +                   use mysql_stmt_result_metadata.
  1418. +  error          - where to write a truncation error if it is present.
  1419. +                   possible error value is:
  1420. +                   0  no truncation
  1421. +                   1  value is out of range or buffer is too small
  1422. +
  1423. +  Please note that MYSQL_BIND also has internals members.
  1424. +*/
  1425. +
  1426. +typedef struct st_mysql_bind
  1427. +{
  1428. +  unsigned long    *length;          /* output length pointer */
  1429. +  my_bool       *is_null;    /* Pointer to null indicator */
  1430. +  void     *buffer;      /* buffer to get/put data */
  1431. +  /* set this if you want to track data truncations happened during fetch */
  1432. +  my_bool       *error;
  1433. +  unsigned char *row_ptr;         /* for the current data position */
  1434. +  void (*store_param_func)(NET *net, struct st_mysql_bind *param);
  1435. +  void (*fetch_result)(struct st_mysql_bind *, MYSQL_FIELD *,
  1436. +                       unsigned char **row);
  1437. +  void (*skip_result)(struct st_mysql_bind *, MYSQL_FIELD *,
  1438. +             unsigned char **row);
  1439. +  /* output buffer length, must be set when fetching str/binary */
  1440. +  unsigned long buffer_length;
  1441. +  unsigned long offset;           /* offset position for char/binary fetch */
  1442. +  unsigned long    length_value;     /* Used if length is 0 */
  1443. +  unsigned int param_number;     /* For null count and error messages */
  1444. +  unsigned int  pack_length;     /* Internal length for packed data */
  1445. +  enum enum_field_types buffer_type;   /* buffer type */
  1446. +  my_bool       error_value;      /* used if error is 0 */
  1447. +  my_bool       is_unsigned;      /* set if integer type is unsigned */
  1448. +  my_bool  long_data_used;   /* If used with mysql_send_long_data */
  1449. +  my_bool  is_null_value;    /* Used if is_null is 0 */
  1450. +  void *extension;
  1451. +} MYSQL_BIND;
  1452. +
  1453. +
  1454. +/* statement handler */
  1455. +typedef struct st_mysql_stmt
  1456. +{
  1457. +  MEM_ROOT       mem_root;             /* root allocations */
  1458. +  LIST           list;                 /* list to keep track of all stmts */
  1459. +  MYSQL          *mysql;               /* connection handle */
  1460. +  MYSQL_BIND     *params;              /* input parameters */
  1461. +  MYSQL_BIND     *bind;                /* output parameters */
  1462. +  MYSQL_FIELD    *fields;              /* result set metadata */
  1463. +  MYSQL_DATA     result;               /* cached result set */
  1464. +  MYSQL_ROWS     *data_cursor;         /* current row in cached result */
  1465. +  /*
  1466. +    mysql_stmt_fetch() calls this function to fetch one row (it's different
  1467. +    for buffered, unbuffered and cursor fetch).
  1468. +  */
  1469. +  int            (*read_row_func)(struct st_mysql_stmt *stmt,
  1470. +                                  unsigned char **row);
  1471. +  /* copy of mysql->affected_rows after statement execution */
  1472. +  my_ulonglong   affected_rows;
  1473. +  my_ulonglong   insert_id;            /* copy of mysql->insert_id */
  1474. +  unsigned long     stmt_id;          /* Id for prepared statement */
  1475. +  unsigned long  flags;                /* i.e. type of cursor to open */
  1476. +  unsigned long  prefetch_rows;        /* number of rows per one COM_FETCH */
  1477. +  /*
  1478. +    Copied from mysql->server_status after execute/fetch to know
  1479. +    server-side cursor status for this statement.
  1480. +  */
  1481. +  unsigned int   server_status;
  1482. +  unsigned int  last_errno;           /* error code */
  1483. +  unsigned int   param_count;          /* input parameter count */
  1484. +  unsigned int   field_count;          /* number of columns in result set */
  1485. +  enum enum_mysql_stmt_state state;    /* statement state */
  1486. +  char      last_error[MYSQL_ERRMSG_SIZE]; /* error message */
  1487. +  char      sqlstate[SQLSTATE_LENGTH+1];
  1488. +  /* Types of input parameters should be sent to server */
  1489. +  my_bool        send_types_to_server;
  1490. +  my_bool        bind_param_done;      /* input buffers were supplied */
  1491. +  unsigned char  bind_result_done;     /* output buffers were supplied */
  1492. +  /* mysql_stmt_close() had to cancel this result */
  1493. +  my_bool       unbuffered_fetch_cancelled;  
  1494. +  /*
  1495. +    Is set to true if we need to calculate field->max_length for
  1496. +    metadata fields when doing mysql_stmt_store_result.
  1497. +  */
  1498. +  my_bool       update_max_length;    
  1499. +  void *extension;
  1500. +} MYSQL_STMT;
  1501. +
  1502. +enum enum_stmt_attr_type
  1503. +{
  1504. +  /*
  1505. +    When doing mysql_stmt_store_result calculate max_length attribute
  1506. +    of statement metadata. This is to be consistent with the old API,
  1507. +    where this was done automatically.
  1508. +    In the new API we do that only by request because it slows down
  1509. +    mysql_stmt_store_result sufficiently.
  1510. +  */
  1511. +  STMT_ATTR_UPDATE_MAX_LENGTH,
  1512. +  /*
  1513. +    unsigned long with combination of cursor flags (read only, for update,
  1514. +    etc)
  1515. +  */
  1516. +  STMT_ATTR_CURSOR_TYPE,
  1517. +  /*
  1518. +    Amount of rows to retrieve from server per one fetch if using cursors.
  1519. +    Accepts unsigned long attribute in the range 1 - ulong_max
  1520. +  */
  1521. +  STMT_ATTR_PREFETCH_ROWS
  1522. +};
  1523. +
  1524. +
  1525. +typedef struct st_mysql_methods
  1526. +{
  1527. +  my_bool (*read_query_result)(MYSQL *mysql);
  1528. +  my_bool (*advanced_command)(MYSQL *mysql,
  1529. +                 enum enum_server_command command,
  1530. +                 const unsigned char *header,
  1531. +                 unsigned long header_length,
  1532. +                 const unsigned char *arg,
  1533. +                 unsigned long arg_length,
  1534. +                 my_bool skip_check,
  1535. +                              MYSQL_STMT *stmt);
  1536. +  MYSQL_DATA *(*read_rows)(MYSQL *mysql,MYSQL_FIELD *mysql_fields,
  1537. +              unsigned int fields);
  1538. +  MYSQL_RES * (*use_result)(MYSQL *mysql);
  1539. +  void (*fetch_lengths)(unsigned long *to,
  1540. +           MYSQL_ROW column, unsigned int field_count);
  1541. +  void (*flush_use_result)(MYSQL *mysql, my_bool flush_all_results);
  1542. +#if !defined(MYSQL_SERVER) || defined(EMBEDDED_LIBRARY)
  1543. +  MYSQL_FIELD * (*list_fields)(MYSQL *mysql);
  1544. +  my_bool (*read_prepare_result)(MYSQL *mysql, MYSQL_STMT *stmt);
  1545. +  int (*stmt_execute)(MYSQL_STMT *stmt);
  1546. +  int (*read_binary_rows)(MYSQL_STMT *stmt);
  1547. +  int (*unbuffered_fetch)(MYSQL *mysql, char **row);
  1548. +  void (*free_embedded_thd)(MYSQL *mysql);
  1549. +  const char *(*read_statistics)(MYSQL *mysql);
  1550. +  my_bool (*next_result)(MYSQL *mysql);
  1551. +  int (*read_change_user_result)(MYSQL *mysql, char *buff, const char *passwd);
  1552. +  int (*read_rows_from_cursor)(MYSQL_STMT *stmt);
  1553. +#endif
  1554. +} MYSQL_METHODS;
  1555. +
  1556. +class DllLibMySQLInterface
  1557. +{
  1558. +public:
  1559. +    virtual ~DllLibMySQLInterface() {}
  1560. +   virtual int mysql_server_init(int argc, char **argv, char **groups)=0;
  1561. +   virtual void mysql_server_end();
  1562. +   virtual MYSQL_PARAMETERS mysql_get_parameters();
  1563. +   virtual my_bool mysql_thread_init()=0;
  1564. +   virtual void mysql_thread_end();
  1565. +   virtual long long mysql_num_rows(MYSQL_RES *res)=0;
  1566. +   virtual unsigned int mysql_num_fields(MYSQL_RES *res)=0;
  1567. +   virtual my_bool mysql_eof(MYSQL_RES *res)=0;
  1568. +   virtual MYSQL_FIELD* mysql_fetch_field_direct(MYSQL_RES *res, unsigned int fieldnr);
  1569. +   virtual MYSQL_FIELD* mysql_fetch_fields(MYSQL_RES *res);
  1570. +   virtual MYSQL_ROW_OFFSET* mysql_row_tell(MYSQL_RES *res);
  1571. +   virtual MYSQL_FIELD_OFFSET* mysql_field_tell(MYSQL_RES *res);
  1572. +   virtual unsigned int mysql_field_count(MYSQL *mysql)=0;
  1573. +   virtual my_ulonglong mysql_affected_rows(MYSQL *mysql)=0;
  1574. +   virtual my_ulonglong mysql_insert_id(MYSQL *mysql)=0;
  1575. +   virtual unsigned int mysql_errno(MYSQL *mysql)=0;
  1576. +   virtual const char mysql_error(MYSQL *mysql)=0;
  1577. +   virtual const char mysql_sqlstate(MYSQL *mysql)=0;
  1578. +   virtual unsigned int mysql_warning_count(MYSQL *mysql)=0;
  1579. +   virtual const char mysql_info(MYSQL *mysql)=0;
  1580. +   virtual unsigned long mysql_thread_id(MYSQL *mysql)=0;
  1581. +   virtual const char mysql_character_set_name(MYSQL *mysql)=0;
  1582. +   virtual int mysql_set_character_set(MYSQL *mysql, const char *csname)=0;
  1583. +   virtual MYSQL* mysql_init(MYSQL *mysql);
  1584. +   virtual my_bool mysql_ssl_set(MYSQL *mysql, const char *key, const char *cert, const char *ca, const char *capath, const char *cipher)=0;
  1585. +   virtual const char mysql_get_ssl_cipher(MYSQL *mysql)=0;
  1586. +   virtual my_bool mysql_change_user(MYSQL *mysql, const char *user, const char *passwd, const char *db)=0;
  1587. +   virtual MYSQL* mysql_real_connect(MYSQL *mysql, const char *host, const char *user, const char *passwd, const char *db, unsigned int port, const char *unix_socket, unsigned long clientflag);
  1588. +   virtual int mysql_select_db(MYSQL *mysql, const char *db)=0;
  1589. +   virtual int mysql_query(MYSQL *mysql, const char *q)=0;
  1590. +   virtual int mysql_send_query(MYSQL *mysql, const char *q, unsigned long length)=0;
  1591. +   virtual int mysql_real_query(MYSQL *mysql, const char *q, unsigned long length)=0;
  1592. +   virtual MYSQL_RES* mysql_store_result(MYSQL *mysql);
  1593. +   virtual MYSQL_RES* mysql_use_result(MYSQL *mysql);
  1594. +   virtual void mysql_get_character_set_info(MYSQL *mysql, MY_CHARSET_INFO *charset);
  1595. +   virtual void mysql_set_local_infile_handler(MYSQL *mysql,
  1596. +       int (*local_infile_init)(void **, const char *, void *),
  1597. +       int (*local_infile_read)(void *, char *, unsigned int),
  1598. +       void (*local_infile_end)(void *),
  1599. +       int (*local_infile_error)(void *, char*, unsigned int),
  1600. +       void *);
  1601. +   virtual void mysql_set_local_infile_default(MYSQL *mysql);
  1602. +   virtual int mysql_shutdown(MYSQL *mysql, enum mysql_enum_shutdown_level shutdown_level)=0;
  1603. +   virtual int mysql_dump_debug_info(MYSQL *mysql)=0;
  1604. +   virtual int mysql_refresh(MYSQL *mysql, unsigned int refresh_options)=0;
  1605. +   virtual int mysql_kill(MYSQL *mysql,unsigned long pid)=0;
  1606. +   virtual int mysql_set_server_option(MYSQL *mysql, enum enum_mysql_set_option option)=0;
  1607. +   virtual int mysql_ping(MYSQL *mysql)=0;
  1608. +   virtual const char mysql_stat(MYSQL *mysql)=0;
  1609. +   virtual const char mysql_get_server_info(MYSQL *mysql)=0;
  1610. +   virtual const char mysql_get_client_info()=0;
  1611. +   virtual unsigned long mysql_get_client_version()=0;
  1612. +   virtual const char mysql_get_host_info(MYSQL *mysql)=0;
  1613. +   virtual unsigned long mysql_get_server_version(MYSQL *mysql)=0;
  1614. +   virtual unsigned int mysql_get_proto_info(MYSQL *mysql)=0;
  1615. +   virtual MYSQL_RES* mysql_list_dbs(MYSQL *mysql,const char *wild);
  1616. +   virtual MYSQL_RES* mysql_list_tables(MYSQL *mysql,const char *wild);
  1617. +   virtual MYSQL_RES* mysql_list_processes(MYSQL *mysql);
  1618. +   virtual int mysql_options(MYSQL *mysql,enum mysql_option option, const void *arg)=0;
  1619. +   virtual void mysql_free_result(MYSQL_RES *result);
  1620. +   virtual void mysql_data_seek(MYSQL_RES *result, my_ulonglong offset);
  1621. +   virtual MYSQL_ROW_OFFSET* mysql_row_seek(MYSQL_RES *result, MYSQL_ROW_OFFSET offset);
  1622. +   virtual MYSQL_FIELD_OFFSET* mysql_field_seek(MYSQL_RES *result, MYSQL_FIELD_OFFSET offset);
  1623. +   virtual MYSQL_ROW mysql_fetch_row(MYSQL_RES *result);
  1624. +   virtual unsigned long* mysql_fetch_lengths(MYSQL_RES *result)=0;
  1625. +   virtual MYSQL_FIELD* mysql_fetch_field(MYSQL_RES *result);
  1626. +   virtual MYSQL_RES* mysql_list_fields(MYSQL *mysql, const char *table, const char *wild);
  1627. +   virtual unsigned long mysql_escape_string(char *to,const char *from, unsigned long from_length)=0;
  1628. +   virtual unsigned long mysql_hex_string(char *to,const char *from, unsigned long from_length)=0;
  1629. +   virtual unsigned long mysql_real_escape_string(MYSQL *mysql, char *to,const char *from, unsigned long length)=0;
  1630. +   virtual void mysql_debug(const char *debug);
  1631. +   virtual void myodbc_remove_escape(MYSQL *mysql,char *name);
  1632. +   virtual unsigned int mysql_thread_safe(void)=0;
  1633. +   virtual my_bool mysql_embedded(void)=0;
  1634. +   virtual my_bool mysql_read_query_result(MYSQL *mysql)=0;
  1635. +   virtual MYSQL_STMT* mysql_stmt_init(MYSQL *mysql);
  1636. +   virtual int mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, unsigned long length)=0;
  1637. +   virtual int mysql_stmt_execute(MYSQL_STMT *stmt)=0;
  1638. +   virtual int mysql_stmt_fetch(MYSQL_STMT *stmt)=0;
  1639. +   virtual int mysql_stmt_fetch_column(MYSQL_STMT *stmt, MYSQL_BIND *bind_arg, unsigned int column, unsigned long offset)=0;
  1640. +   virtual int mysql_stmt_store_result(MYSQL_STMT *stmt)=0;
  1641. +   virtual unsigned long mysql_stmt_param_count(MYSQL_STMT * stmt)=0;
  1642. +   virtual my_bool mysql_stmt_attr_set(MYSQL_STMT *stmt, enum enum_stmt_attr_type attr_type, const void *attr)=0;
  1643. +   virtual my_bool mysql_stmt_attr_get(MYSQL_STMT *stmt, enum enum_stmt_attr_type attr_type, void *attr)=0;
  1644. +   virtual my_bool mysql_stmt_bind_param(MYSQL_STMT * stmt, MYSQL_BIND * bnd)=0;
  1645. +   virtual my_bool mysql_stmt_bind_result(MYSQL_STMT * stmt, MYSQL_BIND * bnd)=0;
  1646. +   virtual my_bool mysql_stmt_close(MYSQL_STMT * stmt)=0;
  1647. +   virtual my_bool mysql_stmt_reset(MYSQL_STMT * stmt)=0;
  1648. +   virtual my_bool mysql_stmt_free_result(MYSQL_STMT *stmt)=0;
  1649. +   virtual my_bool mysql_stmt_send_long_data(MYSQL_STMT *stmt, unsigned int param_number, const char *data, unsigned long length)=0;
  1650. +   virtual MYSQL_RES* mysql_stmt_result_metadata(MYSQL_STMT *stmt);
  1651. +   virtual MYSQL_RES* mysql_stmt_param_metadata(MYSQL_STMT *stmt);
  1652. +   virtual unsigned int mysql_stmt_errno(MYSQL_STMT * stmt)=0;
  1653. +   virtual const char mysql_stmt_error(MYSQL_STMT * stmt)=0;
  1654. +   virtual const char mysql_stmt_sqlstate(MYSQL_STMT * stmt)=0;
  1655. +   virtual MYSQL_ROW_OFFSET* mysql_stmt_row_seek(MYSQL_STMT *stmt, MYSQL_ROW_OFFSET offset);
  1656. +   virtual MYSQL_ROW_OFFSET* mysql_stmt_row_tell(MYSQL_STMT *stmt);
  1657. +   virtual void mysql_stmt_data_seek(MYSQL_STMT *stmt, my_ulonglong offset);
  1658. +   virtual my_ulonglong mysql_stmt_num_rows(MYSQL_STMT *stmt)=0;
  1659. +   virtual my_ulonglong mysql_stmt_affected_rows(MYSQL_STMT *stmt)=0;
  1660. +   virtual my_ulonglong mysql_stmt_insert_id(MYSQL_STMT *stmt)=0;
  1661. +   virtual unsigned int mysql_stmt_field_count(MYSQL_STMT *stmt)=0;
  1662. +   virtual my_bool mysql_commit(MYSQL * mysql)=0;
  1663. +   virtual my_bool mysql_rollback(MYSQL * mysql)=0;
  1664. +   virtual my_bool mysql_autocommit(MYSQL * mysql, my_bool auto_mode)=0;
  1665. +   virtual my_bool mysql_more_results(MYSQL *mysql)=0;
  1666. +   virtual int mysql_next_result(MYSQL *mysql)=0;
  1667. +   virtual int mysql_stmt_next_result(MYSQL_STMT *stmt)=0;
  1668. +   virtual void mysql_close(MYSQL *sock);
  1669. +};
  1670. +
  1671. +class DllLibMySQL : public DllDynamic, DllLibMySQLInterface
  1672. +{
  1673. +   DECLARE_DLL_WRAPPER(DllLibMySQL, Q:\\system\\libMySQL.dll)
  1674. +   DEFINE_METHOD3(int,mysql_server_init,(int p1, char **p2, char **p3));
  1675. +   DEFINE_METHOD0(my_bool,mysql_thread_init);
  1676. +   DEFINE_METHOD1(long long, mysql_num_rows,(MYSQL_RES *p1));
  1677. +   DEFINE_METHOD1(my_bool, mysql_eof, (MYSQL_RES *p1));
  1678. +   DEFINE_METHOD1(unsigned int, mysql_num_fields, (MYSQL_RES *p1));
  1679. +   DEFINE_METHOD1(MYSQL_ROW_OFFSET*, mysql_row_tell, (MYSQL_RES *p1))
  1680. +   DEFINE_METHOD1(MYSQL_FIELD_OFFSET*, mysql_field_tell, (MYSQL_RES *p1))
  1681. +   DEFINE_METHOD1(unsigned int, mysql_field_count, (MYSQL *p1))
  1682. +   DEFINE_METHOD1(my_ulonglong, mysql_affected_rows, (MYSQL *p1))
  1683. +   DEFINE_METHOD1(my_ulonglong, mysql_insert_id, (MYSQL *p1))
  1684. +   DEFINE_METHOD1(unsigned int, mysql_errno, (MYSQL *p1))
  1685. +   DEFINE_METHOD1(const char, mysql_error, (MYSQL *p1))
  1686. +   DEFINE_METHOD1(const char, mysql_sqlstate, (MYSQL *p1))
  1687. +   DEFINE_METHOD1(unsigned int, mysql_warning_count, (MYSQL *p1))
  1688. +   DEFINE_METHOD1(const char, mysql_info, (MYSQL *p1))
  1689. +   DEFINE_METHOD1(unsigned long, mysql_thread_id, (MYSQL *p1))
  1690. +   DEFINE_METHOD1(const char, mysql_character_set_name, (MYSQL *p1))
  1691. +   DEFINE_METHOD2(int, mysql_set_character_set, (MYSQL *p1, const char *p2))
  1692. +   DEFINE_METHOD1(MYSQL*, mysql_init, (MYSQL *p1))
  1693. +   DEFINE_METHOD6(my_bool, mysql_ssl_set, (MYSQL *p1, const char *p2, const char *p3, const char *p4, const char *p5, const char *p6))
  1694. +   DEFINE_METHOD1(const char, mysql_get_ssl_cipher, (MYSQL *p1))
  1695. +   DEFINE_METHOD4(my_bool, mysql_change_user, (MYSQL *p1, const char *p2, const char *p3, const char *p4))
  1696. +   DEFINE_METHOD7(MYSQL*, mysql_real_connect, (MYSQL *p1, const char *p2, const char *p3, const char *p4, const char *p5, unsigned int p6, const char *p7))
  1697. +   DEFINE_METHOD2(int, mysql_select_db, (MYSQL *p1, const char *p2))
  1698. +   DEFINE_METHOD2(int, mysql_query, (MYSQL *p1, const char *p2))
  1699. +   DEFINE_METHOD3(int, mysql_send_query, (MYSQL *p1, const char *p2, unsigned long p3))
  1700. +   DEFINE_METHOD3(int, mysql_real_query, (MYSQL *p1, const char *p2, unsigned long p3))
  1701. +   DEFINE_METHOD1(MYSQL_RES*, mysql_store_result, (MYSQL *p1))
  1702. +   DEFINE_METHOD1(MYSQL_RES*, mysql_use_result, (MYSQL *p1))
  1703. +   DEFINE_METHOD2(void, mysql_get_character_set_info, (MYSQL *p1, MY_CHARSET_INFO *p2))
  1704. +   DEFINE_METHOD1(void, mysql_set_local_infile_default, (MYSQL *p1))
  1705. +   DEFINE_METHOD2(int, mysql_shutdown, (MYSQL *p1, enum mysql_enum_shutdown_level p2))
  1706. +   DEFINE_METHOD1(int, mysql_dump_debug_info, (MYSQL *p1))
  1707. +   DEFINE_METHOD2(int, mysql_refresh, (MYSQL *p1, unsigned int p2))
  1708. +   DEFINE_METHOD2(int, mysql_kill, (MYSQL *p1, unsigned long p2))
  1709. +   DEFINE_METHOD2(int, mysql_set_server_option, (MYSQL *p1, enum enum_mysql_set_option p2))
  1710. +   DEFINE_METHOD1(int, mysql_ping, (MYSQL *p1))
  1711. +   DEFINE_METHOD1(const char, mysql_stat, (MYSQL *p1))
  1712. +   DEFINE_METHOD1(const char, mysql_get_server_info, (MYSQL *p1))
  1713. +   DEFINE_METHOD0(const char, mysql_get_client_info)
  1714. +   DEFINE_METHOD0(unsigned long, mysql_get_client_version)
  1715. +   DEFINE_METHOD1(const char, mysql_get_host_info, (MYSQL *p1))
  1716. +   DEFINE_METHOD1(unsigned long, mysql_get_server_version, (MYSQL *p1))
  1717. +   DEFINE_METHOD1(unsigned int, mysql_get_proto_info, (MYSQL *p1))
  1718. +   DEFINE_METHOD2(MYSQL_RES*, mysql_list_dbs, (MYSQL *p1, const char *p2))
  1719. +   DEFINE_METHOD2(MYSQL_RES*, mysql_list_tables, (MYSQL *p1, const char *p2))
  1720. +   DEFINE_METHOD1(MYSQL_RES*, mysql_list_processes, (MYSQL *p1))
  1721. +   DEFINE_METHOD3(int, mysql_options, (MYSQL *p1, enum mysql_option p2, const void *p3))
  1722. +   DEFINE_METHOD1(void, mysql_free_result, (MYSQL_RES *p1))
  1723. +   DEFINE_METHOD2(void, mysql_data_seek, (MYSQL_RES *p1, my_ulonglong p2))
  1724. +   DEFINE_METHOD2(MYSQL_ROW_OFFSET*, mysql_row_seek, (MYSQL_RES *p1, MYSQL_ROW_OFFSET p2))
  1725. +   DEFINE_METHOD2(MYSQL_FIELD_OFFSET*, mysql_field_seek, (MYSQL_RES *p1, MYSQL_FIELD_OFFSET p2))
  1726. +   DEFINE_METHOD1(MYSQL_ROW, mysql_fetch_row, (MYSQL_RES *p1))
  1727. +   DEFINE_METHOD1(unsigned long*, mysql_fetch_lengths, (MYSQL_RES *p1))
  1728. +   DEFINE_METHOD1(MYSQL_FIELD*, mysql_fetch_field, (MYSQL_RES *p1))
  1729. +   DEFINE_METHOD1(MYSQL_FIELD*, mysql_fetch_fields, (MYSQL_RES *p1))
  1730. +   DEFINE_METHOD3(MYSQL_RES*, mysql_list_fields, (MYSQL *p1, const char *p2, const char *p3))
  1731. +   DEFINE_METHOD3(unsigned long, mysql_escape_string, (char *p1, const char *p2, unsigned long p3))
  1732. +   DEFINE_METHOD3(unsigned long, mysql_hex_string, (char *p1, const char *p2, unsigned long p3))
  1733. +   DEFINE_METHOD4(unsigned long, mysql_real_escape_string, (MYSQL *p1, char *p2, const char *p3, unsigned long p4))
  1734. +   DEFINE_METHOD1(void, mysql_debug, (const char *p1))
  1735. +   DEFINE_METHOD2(void, myodbc_remove_escape, (MYSQL *p1, char *p2))
  1736. +   DEFINE_METHOD0(unsigned int, mysql_thread_safe)
  1737. +   DEFINE_METHOD0(my_bool, mysql_embedded)
  1738. +   DEFINE_METHOD1(my_bool, mysql_read_query_result, (MYSQL *p1))
  1739. +   DEFINE_METHOD1(MYSQL_STMT*, mysql_stmt_init, (MYSQL *p1))
  1740. +   DEFINE_METHOD3(int, mysql_stmt_prepare, (MYSQL_STMT *p1, const char *p2, unsigned long p3))
  1741. +   DEFINE_METHOD1(int, mysql_stmt_execute, (MYSQL_STMT *p1))
  1742. +   DEFINE_METHOD1(int, mysql_stmt_fetch, (MYSQL_STMT *p1))
  1743. +   DEFINE_METHOD4(int, mysql_stmt_fetch_column, (MYSQL_STMT *p1, MYSQL_BIND *p2, unsigned int p3, unsigned long p4))
  1744. +   DEFINE_METHOD1(int, mysql_stmt_store_result, (MYSQL_STMT *p1))
  1745. +   DEFINE_METHOD1(unsigned long, mysql_stmt_param_count, (MYSQL_STMT *p1))
  1746. +   DEFINE_METHOD3(my_bool, mysql_stmt_attr_set, (MYSQL_STMT *p1, enum enum_stmt_attr_type p2, const void *p3))
  1747. +   DEFINE_METHOD3(my_bool, mysql_stmt_attr_get, (MYSQL_STMT *p1, enum enum_stmt_attr_type p2, void *p3))
  1748. +   DEFINE_METHOD2(my_bool, mysql_stmt_bind_param, (MYSQL_STMT *p1, MYSQL_BIND *p2))
  1749. +   DEFINE_METHOD2(my_bool, mysql_stmt_bind_result, (MYSQL_STMT *p1, MYSQL_BIND *p2))
  1750. +   DEFINE_METHOD1(my_bool, mysql_stmt_close, (MYSQL_STMT *p1))
  1751. +   DEFINE_METHOD1(my_bool, mysql_stmt_reset, (MYSQL_STMT *p1))
  1752. +   DEFINE_METHOD1(my_bool, mysql_stmt_free_result, (MYSQL_STMT *p1))
  1753. +   DEFINE_METHOD4(my_bool, mysql_stmt_send_long_data, (MYSQL_STMT *p1, unsigned int p2, const char *p3, unsigned long p4))
  1754. +   DEFINE_METHOD1(MYSQL_RES*, mysql_stmt_result_metadata, (MYSQL_STMT *p1))
  1755. +   DEFINE_METHOD1(MYSQL_RES*, mysql_stmt_param_metadata, (MYSQL_STMT *p1))
  1756. +   DEFINE_METHOD1(unsigned int, mysql_stmt_errno, (MYSQL_STMT *p1))
  1757. +   DEFINE_METHOD1(const char, mysql_stmt_error, (MYSQL_STMT *p1))
  1758. +   DEFINE_METHOD1(const char, mysql_stmt_sqlstate, (MYSQL_STMT *p1))
  1759. +   DEFINE_METHOD2(MYSQL_ROW_OFFSET*, mysql_stmt_row_seek, (MYSQL_STMT *p1, MYSQL_ROW_OFFSET p2))
  1760. +   DEFINE_METHOD1(MYSQL_ROW_OFFSET*, mysql_stmt_row_tell, (MYSQL_STMT *p1))
  1761. +   DEFINE_METHOD2(void, mysql_stmt_data_seek, (MYSQL_STMT *p1, my_ulonglong p2))
  1762. +   DEFINE_METHOD1(my_ulonglong, mysql_stmt_num_rows, (MYSQL_STMT *p1))
  1763. +   DEFINE_METHOD1(my_ulonglong, mysql_stmt_affected_rows, (MYSQL_STMT *p1))
  1764. +   DEFINE_METHOD1(my_ulonglong, mysql_stmt_insert_id, (MYSQL_STMT *p1))
  1765. +   DEFINE_METHOD1(unsigned int, mysql_stmt_field_count, (MYSQL_STMT *p1))
  1766. +   DEFINE_METHOD1(my_bool, mysql_commit, (MYSQL *p1))
  1767. +   DEFINE_METHOD1(my_bool, mysql_rollback, (MYSQL *p1))
  1768. +   DEFINE_METHOD2(my_bool, mysql_autocommit, (MYSQL *p1, my_bool p2))
  1769. +   DEFINE_METHOD1(my_bool, mysql_more_results, (MYSQL *p1))
  1770. +   DEFINE_METHOD1(int, mysql_next_result, (MYSQL *p1))
  1771. +   DEFINE_METHOD1(int, mysql_stmt_next_result, (MYSQL_STMT *p1))
  1772. +   DEFINE_METHOD1(void, mysql_close, (MYSQL *p1))
  1773. +   DEFINE_METHOD6(void, mysql_set_local_infile_handler, (MYSQL *p1, int (*p2)(void **, const char *, void *), int (*p3)(void *, char *, unsigned int), void (*p4)(void *), int (*p5)(void *, char*, unsigned int), void *p6))
  1774. +
  1775. +   BEGIN_METHOD_RESOLVE()
  1776. +       RESOLVE_METHOD(mysql_server_init)
  1777. +       RESOLVE_METHOD(mysql_thread_init)
  1778. +       RESOLVE_METHOD(mysql_num_rows)
  1779. +       RESOLVE_METHOD(mysql_num_fields)
  1780. +       RESOLVE_METHOD(mysql_row_tell)
  1781. +       RESOLVE_METHOD(mysql_eof)
  1782. +       RESOLVE_METHOD(mysql_field_tell)
  1783. +       RESOLVE_METHOD(mysql_field_count)
  1784. +       RESOLVE_METHOD(mysql_affected_rows)
  1785. +       RESOLVE_METHOD(mysql_insert_id)
  1786. +       RESOLVE_METHOD(mysql_errno)
  1787. +       RESOLVE_METHOD(mysql_error)
  1788. +       RESOLVE_METHOD(mysql_sqlstate)
  1789. +       RESOLVE_METHOD(mysql_warning_count)
  1790. +       RESOLVE_METHOD(mysql_info)
  1791. +       RESOLVE_METHOD(mysql_thread_id)
  1792. +       RESOLVE_METHOD(mysql_character_set_name)
  1793. +       RESOLVE_METHOD(mysql_set_character_set)
  1794. +       RESOLVE_METHOD(mysql_init)
  1795. +       RESOLVE_METHOD(mysql_ssl_set)
  1796. +       RESOLVE_METHOD(mysql_get_ssl_cipher)
  1797. +       RESOLVE_METHOD(mysql_change_user)
  1798. +       RESOLVE_METHOD(mysql_real_connect)
  1799. +       RESOLVE_METHOD(mysql_select_db)
  1800. +       RESOLVE_METHOD(mysql_query)
  1801. +       RESOLVE_METHOD(mysql_send_query)
  1802. +       RESOLVE_METHOD(mysql_real_query)
  1803. +       RESOLVE_METHOD(mysql_store_result)
  1804. +       RESOLVE_METHOD(mysql_use_result)
  1805. +       RESOLVE_METHOD(mysql_get_character_set_info)
  1806. +       RESOLVE_METHOD(mysql_set_local_infile_default)
  1807. +       RESOLVE_METHOD(mysql_shutdown)
  1808. +       RESOLVE_METHOD(mysql_dump_debug_info)
  1809. +       RESOLVE_METHOD(mysql_refresh)
  1810. +       RESOLVE_METHOD(mysql_kill)
  1811. +       RESOLVE_METHOD(mysql_set_server_option)
  1812. +       RESOLVE_METHOD(mysql_ping)
  1813. +       RESOLVE_METHOD(mysql_stat)
  1814. +       RESOLVE_METHOD(mysql_get_server_info)
  1815. +       RESOLVE_METHOD(mysql_get_client_info)
  1816. +       RESOLVE_METHOD(mysql_get_client_version)
  1817. +       RESOLVE_METHOD(mysql_get_host_info)
  1818. +       RESOLVE_METHOD(mysql_get_server_version)
  1819. +       RESOLVE_METHOD(mysql_get_proto_info)
  1820. +       RESOLVE_METHOD(mysql_list_dbs)
  1821. +       RESOLVE_METHOD(mysql_list_tables)
  1822. +       RESOLVE_METHOD(mysql_list_processes)
  1823. +       RESOLVE_METHOD(mysql_options)
  1824. +       RESOLVE_METHOD(mysql_free_result)
  1825. +       RESOLVE_METHOD(mysql_data_seek)
  1826. +       RESOLVE_METHOD(mysql_row_seek)
  1827. +       RESOLVE_METHOD(mysql_field_seek)
  1828. +       RESOLVE_METHOD(mysql_fetch_row)
  1829. +       RESOLVE_METHOD(mysql_fetch_lengths)
  1830. +       RESOLVE_METHOD(mysql_fetch_field)
  1831. +       RESOLVE_METHOD(mysql_fetch_fields)
  1832. +       RESOLVE_METHOD(mysql_list_fields)
  1833. +       RESOLVE_METHOD(mysql_escape_string)
  1834. +       RESOLVE_METHOD(mysql_hex_string)
  1835. +       RESOLVE_METHOD(mysql_real_escape_string)
  1836. +       RESOLVE_METHOD(mysql_debug)
  1837. +       RESOLVE_METHOD(myodbc_remove_escape)
  1838. +       RESOLVE_METHOD(mysql_thread_safe)
  1839. +       RESOLVE_METHOD(mysql_embedded)
  1840. +       RESOLVE_METHOD(mysql_read_query_result)
  1841. +       RESOLVE_METHOD(mysql_stmt_init)
  1842. +       RESOLVE_METHOD(mysql_stmt_prepare)
  1843. +       RESOLVE_METHOD(mysql_stmt_execute)
  1844. +       RESOLVE_METHOD(mysql_stmt_fetch)
  1845. +       RESOLVE_METHOD(mysql_stmt_fetch_column)
  1846. +       RESOLVE_METHOD(mysql_stmt_store_result)
  1847. +       RESOLVE_METHOD(mysql_stmt_param_count)
  1848. +       RESOLVE_METHOD(mysql_stmt_attr_set)
  1849. +       RESOLVE_METHOD(mysql_stmt_attr_get)
  1850. +       RESOLVE_METHOD(mysql_stmt_bind_param)
  1851. +       RESOLVE_METHOD(mysql_stmt_bind_result)
  1852. +       RESOLVE_METHOD(mysql_stmt_close)
  1853. +       RESOLVE_METHOD(mysql_stmt_reset)
  1854. +       RESOLVE_METHOD(mysql_stmt_free_result)
  1855. +       RESOLVE_METHOD(mysql_stmt_send_long_data)
  1856. +       RESOLVE_METHOD(mysql_stmt_result_metadata)
  1857. +       RESOLVE_METHOD(mysql_stmt_param_metadata)
  1858. +       RESOLVE_METHOD(mysql_stmt_errno)
  1859. +       RESOLVE_METHOD(mysql_stmt_error)
  1860. +       RESOLVE_METHOD(mysql_stmt_sqlstate)
  1861. +       RESOLVE_METHOD(mysql_stmt_row_seek)
  1862. +       RESOLVE_METHOD(mysql_stmt_row_tell)
  1863. +       RESOLVE_METHOD(mysql_stmt_data_seek)
  1864. +       RESOLVE_METHOD(mysql_stmt_num_rows)
  1865. +       RESOLVE_METHOD(mysql_stmt_affected_rows)
  1866. +       RESOLVE_METHOD(mysql_stmt_insert_id)
  1867. +       RESOLVE_METHOD(mysql_stmt_field_count)
  1868. +       RESOLVE_METHOD(mysql_commit)
  1869. +       RESOLVE_METHOD(mysql_rollback)
  1870. +       RESOLVE_METHOD(mysql_autocommit)
  1871. +       RESOLVE_METHOD(mysql_more_results)
  1872. +       RESOLVE_METHOD(mysql_next_result)
  1873. +       RESOLVE_METHOD(mysql_stmt_next_result)
  1874. +       RESOLVE_METHOD(mysql_close)
  1875. +   END_METHOD_RESOLVE()
  1876. +};
  1877. Index: xbmc/lib/sqLite/mysqldataset.cpp
  1878. ===================================================================
  1879. --- xbmc/lib/sqLite/mysqldataset.cpp    (revision 0)
  1880. +++ xbmc/lib/sqLite/mysqldataset.cpp    (working copy)
  1881. @@ -0,0 +1,682 @@
  1882. +/*
  1883. + *      Copyright (C) 2005-2009 Team XBMC
  1884. + *      http://xbmc.org
  1885. + *
  1886. + *  This Program is free software; you can redistribute it and/or modify
  1887. + *  it under the terms of the GNU General Public License as published by
  1888. + *  the Free Software Foundation; either version 2, or (at your option)
  1889. + *  any later version.
  1890. + *
  1891. + *  This Program is distributed in the hope that it will be useful,
  1892. + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  1893. + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1894. + *  GNU General Public License for more details.
  1895. + *
  1896. + *  You should have received a copy of the GNU General Public License
  1897. + *  along with XBMC; see the file COPYING.  If not, write to
  1898. + *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  1899. + *  http://www.gnu.org/copyleft/gpl.html
  1900. + *
  1901. + */
  1902. +
  1903. +#include <iostream>
  1904. +#include <string>
  1905. +#include <set>
  1906. +
  1907. +#include "mysqldataset.h"
  1908. +#include "utils/log.h"
  1909. +#include "system.h" // for GetLastError()
  1910. +#include "errmsg.h"
  1911. +
  1912. +
  1913. +#define MYSQL_OK        0
  1914. +
  1915. +using namespace std;
  1916. +
  1917. +namespace dbiplus {
  1918. +
  1919. +//************* MysqlDatabase implementation ***************
  1920. +
  1921. +MysqlDatabase::MysqlDatabase() {
  1922. +
  1923. +  active = false;
  1924. +  _in_transaction = false;     // for transaction
  1925. +
  1926. +  error = "Unknown database error";//S_NO_CONNECTION;
  1927. +  host = "localhost";
  1928. +  port = "3306";
  1929. +  db = "mysql";
  1930. +  login = "root";
  1931. +  passwd = "null";
  1932. +  conn = NULL;
  1933. +  //m_MySQL = new DllLibMySQL;
  1934. +  m_MySQL.Load();
  1935. +}
  1936. +
  1937. +MysqlDatabase::~MysqlDatabase() {
  1938. +  disconnect();
  1939. +  m_MySQL.Unload();
  1940. +}
  1941. +
  1942. +Dataset* MysqlDatabase::CreateDataset() const {
  1943. +   return new MysqlDataset((MysqlDatabase*)this);
  1944. +}
  1945. +
  1946. +int MysqlDatabase::status(void) {
  1947. +  if (active == false) return DB_CONNECTION_NONE;
  1948. +  return DB_CONNECTION_OK;
  1949. +}
  1950. +
  1951. +int MysqlDatabase::setErr(int err_code, const char * qry) {
  1952. +  switch (err_code)
  1953. +  {
  1954. +    case MYSQL_OK:
  1955. +      error = "Successful result";
  1956. +      break;
  1957. +    case CR_COMMANDS_OUT_OF_SYNC:
  1958. +      error = "Commands were executed in an improper order";
  1959. +      break;
  1960. +    case CR_SERVER_GONE_ERROR:
  1961. +      error = "The MySQL server has gone away";
  1962. +      break;
  1963. +    case CR_SERVER_LOST:
  1964. +      error = "The connection to the server was lost during this query";
  1965. +      break;
  1966. +    case CR_UNKNOWN_ERROR:
  1967. +      error = "An unknown error occurred";
  1968. +      break;
  1969. +    case 1146: /* ER_NO_SUCH_TABLE */
  1970. +      error = "The table does not exist";
  1971. +      break;
  1972. +    default:
  1973. +      char err[256];
  1974. +      // snprintf(err, 256, "Undefined MySQL error: Code (%d)", err_code);
  1975. +      error = err;
  1976. +  }
  1977. +  error += "\nQuery: ";
  1978. +  error += qry;
  1979. +  error += "\n";
  1980. +  return err_code;
  1981. +}
  1982. +
  1983. +const char *MysqlDatabase::getErrorMsg() {
  1984. +   return error.c_str();
  1985. +}
  1986. +
  1987. +int MysqlDatabase::connect() {
  1988. +  try
  1989. +  {
  1990. +    // don't reconnect if ping is ok
  1991. +     if (conn != NULL && m_MySQL.mysql_ping(conn) == 0)
  1992. +    {
  1993. +      return DB_CONNECTION_OK;
  1994. +    }
  1995. +    disconnect();
  1996. +
  1997. +    if (conn == NULL)
  1998. +    {
  1999. +       conn = m_MySQL.mysql_init(conn);
  2000. +    }
  2001. +
  2002. +    // TODO block to avoid multiple connect on db
  2003. +    if (m_MySQL.mysql_real_connect(conn,host.c_str(),login.c_str(),passwd.c_str(),db.c_str(),atoi(port.c_str()),NULL) != NULL)
  2004. +    {
  2005. +      active = true;
  2006. +      return DB_CONNECTION_OK;
  2007. +    }
  2008. +    // Database doesn't exists
  2009. +    if (m_MySQL.mysql_errno(conn) == 1049)
  2010. +    {
  2011. +      if (create() == MYSQL_OK)
  2012. +      {
  2013. +        active = true;
  2014. +
  2015. +        // disable mysql autocommit since we handle it
  2016. +        m_MySQL.mysql_autocommit(conn, false);
  2017. +
  2018. +        return DB_CONNECTION_OK;
  2019. +      }
  2020. +    }
  2021. +
  2022. +    CLog::Log(LOGERROR, "Unable to open database:%s [%d](%s)",
  2023. +              db.c_str(), m_MySQL.mysql_errno(conn), m_MySQL.mysql_error(conn));
  2024. +    return DB_CONNECTION_NONE;
  2025. +  }
  2026. +  catch(...)
  2027. +  {
  2028. +    CLog::Log(LOGERROR, "Unable to open database:%s (%u)",
  2029. +              db.c_str(), GetLastError());
  2030. +  }
  2031. +  return DB_CONNECTION_NONE;
  2032. +}
  2033. +
  2034. +void MysqlDatabase::disconnect(void) {
  2035. +  if (active == false) return;
  2036. +  if (conn == NULL) return;
  2037. +  m_MySQL.mysql_close(conn);
  2038. +  conn = NULL;
  2039. +  active = false;
  2040. +}
  2041. +
  2042. +int MysqlDatabase::create() {
  2043. +  const char* seq_table = "sys_seq";
  2044. +  if (m_MySQL.mysql_real_connect(conn, host.c_str(), login.c_str(), passwd.c_str(), NULL, atoi(port.c_str()),NULL) == NULL)
  2045. +  {
  2046. +    throw DbErrors("Can't create database: '%s'\nCan't connect to server",db.c_str());
  2047. +  }
  2048. +  char sqlcmd[512];
  2049. +  sprintf(sqlcmd, "CREATE DATABASE `%s`", db.c_str());
  2050. +  if ( query_with_reconnect(sqlcmd) )
  2051. +  {
  2052. +    throw DbErrors("Can't create database: '%s'\nError: %s", db.c_str(), strerror(errno));
  2053. +  }
  2054. +  // Reconnect to the server
  2055. +  if (m_MySQL.mysql_real_connect(conn, host.c_str(), login.c_str(), passwd.c_str(), db.c_str(), atoi(port.c_str()), NULL) == NULL)
  2056. +  {
  2057. +    throw DbErrors("Can't create database: '%s'\nCan't reconnect to server",db.c_str());
  2058. +  }
  2059. +  // Create the sequence table
  2060. +  sprintf(sqlcmd,"CREATE TABLE `%s` (`seq_name` VARCHAR( 64 ) NOT NULL, `nextid` INT NOT NULL, PRIMARY KEY ( `seq_name` ))", seq_table);
  2061. +  if ( query_with_reconnect(sqlcmd) )
  2062. +  {
  2063. +    throw DbErrors("Can't create sequence table in '%s'\nError: %s", db.c_str(), strerror(errno));
  2064. +  }
  2065. +  return MYSQL_OK;
  2066. +}
  2067. +
  2068. +int MysqlDatabase::drop() {
  2069. +  if (active == false) throw DbErrors("Can't drop database: no active connection...");
  2070. +  char sqlcmd[512];
  2071. +  sprintf(sqlcmd,"DROP DATABASE `%s`", db.c_str());
  2072. +  if ( query_with_reconnect(sqlcmd) )
  2073. +  {
  2074. +    throw DbErrors("Can't drop database: '%s'\nError: %s", db.c_str(), strerror(errno));
  2075. +  }
  2076. +  disconnect();
  2077. +  return DB_COMMAND_OK;
  2078. +}
  2079. +
  2080. +int MysqlDatabase::query_with_reconnect(const char* query) {
  2081. +  int attempts = 5;
  2082. +  int result;
  2083. +
  2084. +  // try to reconnect if server is gone (up to 3 times)
  2085. +  while ( ((result = m_MySQL.mysql_real_query(conn, query, strlen(query))) == CR_SERVER_GONE_ERROR) &&
  2086. +          (attempts-- > 0) )
  2087. +  {
  2088. +    CLog::Log(LOGINFO,"MYSQL server has gone. Will try %d more attempt(s) to reconnect.", attempts);
  2089. +    active = false;
  2090. +    connect();
  2091. +  }
  2092. +
  2093. +  // grab the latest error if not ok
  2094. +  if (result != MYSQL_OK)
  2095. +    result = m_MySQL.mysql_errno(conn);
  2096. +
  2097. +  // set the error return string and return
  2098. +  return result;
  2099. +}
  2100. +
  2101. +long MysqlDatabase::nextid(const char* sname) {
  2102. +  CLog::Log(LOGDEBUG,"MysqlDatabase::nextid for %s",sname);
  2103. +  if (!active) return DB_UNEXPECTED_RESULT;
  2104. +  const char* seq_table = "sys_seq";
  2105. +  int id;/*,nrow,ncol;*/
  2106. +  MYSQL_RES* res;
  2107. +  char sqlcmd[512];
  2108. +  sprintf(sqlcmd,"select nextid from %s where seq_name = '%s'",seq_table, sname);
  2109. +  CLog::Log(LOGDEBUG,"MysqlDatabase::nextid will request");
  2110. +  if ((last_err = query_with_reconnect(sqlcmd)) != 0)
  2111. +  {
  2112. +    return DB_UNEXPECTED_RESULT;
  2113. +  }
  2114. +  res = m_MySQL.mysql_store_result(conn);
  2115. +  if (m_MySQL.mysql_num_rows(res) == 0)
  2116. +  {
  2117. +    id = 1;
  2118. +    sprintf(sqlcmd,"insert into %s (nextid,seq_name) values (%d,'%s')",seq_table,id,sname);
  2119. +    m_MySQL.mysql_free_result(res);
  2120. +    if ((last_err = query_with_reconnect(sqlcmd)) != 0) return DB_UNEXPECTED_RESULT;
  2121. +    return id;
  2122. +  }
  2123. +  else
  2124. +  {
  2125. +    MYSQL_ROW row = m_MySQL.mysql_fetch_row(res);
  2126. +    //id = (int)row[0];
  2127. +    id = -1;
  2128. +    unsigned long *lengths;
  2129. +    lengths = m_MySQL.mysql_fetch_lengths(res);
  2130. +    CLog::Log(LOGINFO,"Next id is [%.*s] ", (int) lengths[0], row[0]);
  2131. +    sprintf(sqlcmd,"update %s set nextid=%d where seq_name = '%s'",seq_table,id,sname);
  2132. +    if ((last_err = query_with_reconnect(sqlcmd) != 0)) return DB_UNEXPECTED_RESULT;
  2133. +    return id;
  2134. +  }
  2135. +  return DB_UNEXPECTED_RESULT;
  2136. +}
  2137. +
  2138. +// methods for transactions
  2139. +// ---------------------------------------------
  2140. +void MysqlDatabase::start_transaction() {
  2141. +  if (active)
  2142. +  {
  2143. +    CLog::Log(LOGDEBUG,"Mysql Start transaction");
  2144. +    _in_transaction = true;
  2145. +  }
  2146. +}
  2147. +
  2148. +void MysqlDatabase::commit_transaction() {
  2149. +  if (active)
  2150. +  {
  2151. +    m_MySQL.mysql_commit(conn);
  2152. +    CLog::Log(LOGDEBUG,"Mysql commit transaction");
  2153. +    _in_transaction = false;
  2154. +  }
  2155. +}
  2156. +
  2157. +void MysqlDatabase::rollback_transaction() {
  2158. +  if (active)
  2159. +  {
  2160. +    m_MySQL.mysql_rollback(conn);
  2161. +    CLog::Log(LOGDEBUG,"Mysql rollback transaction");
  2162. +    _in_transaction = false;
  2163. +  }
  2164. +}
  2165. +
  2166. +bool MysqlDatabase::exists() {
  2167. +  // Uncorrect name, check if tables are present inside the db
  2168. +  connect();
  2169. +  if (active && conn != NULL)
  2170. +  {
  2171. +    MYSQL_RES* res = m_MySQL.mysql_list_dbs(conn, db.c_str());
  2172. +    if (res == NULL)
  2173. +    {
  2174. +      CLog::Log(LOGERROR,"Database is not present, does the user has CREATE DATABASE permission");
  2175. +      return false;
  2176. +    }
  2177. +
  2178. +    bool result = (m_MySQL.mysql_num_rows(res) > 0); // Avoid counting the sequence table
  2179. +    m_MySQL.mysql_free_result(res);
  2180. +    // Check if there is some tables ( to permit user with no create database rights
  2181. +    if (result == true)
  2182. +    {
  2183. +      res = m_MySQL.mysql_list_tables(conn, NULL);
  2184. +      if (res != NULL)
  2185. +      {
  2186. +        result = (m_MySQL.mysql_num_rows(res) > 1);
  2187. +      }
  2188. +      m_MySQL.mysql_free_result(res);
  2189. +    }
  2190. +    return result;
  2191. +  }
  2192. +  return false;
  2193. +}
  2194. +
  2195. +//************* MysqlDataset implementation ***************
  2196. +
  2197. +MysqlDataset::MysqlDataset():Dataset() {
  2198. +  haveError = false;
  2199. +  db = NULL;
  2200. +  errmsg = NULL;
  2201. +  autorefresh = false;
  2202. +}
  2203. +
  2204. +
  2205. +MysqlDataset::MysqlDataset(MysqlDatabase *newDb):Dataset(newDb) {
  2206. +  haveError = false;
  2207. +  db = newDb;
  2208. +  errmsg = NULL;
  2209. +  autorefresh = false;
  2210. +  m_MySQL.Load();
  2211. +}
  2212. +
  2213. +MysqlDataset::~MysqlDataset() {
  2214. +   if (errmsg) free(errmsg);
  2215. +   m_MySQL.Unload();
  2216. + }
  2217. +
  2218. +
  2219. +void MysqlDataset::set_autorefresh(bool val) {
  2220. +    autorefresh = val;
  2221. +}
  2222. +
  2223. +
  2224. +
  2225. +//--------- protected functions implementation -----------------//
  2226. +
  2227. +MYSQL* MysqlDataset::handle(){
  2228. +  if (db != NULL)
  2229. +  {
  2230. +    return static_cast<MysqlDatabase*>(db)->getHandle();
  2231. +  }
  2232. +
  2233. +  return NULL;
  2234. +}
  2235. +
  2236. +void MysqlDataset::make_query(StringList &_sql) {
  2237. +  string query;
  2238. +  int result = 0;
  2239. +  try
  2240. +  {
  2241. +    if (db == NULL) throw DbErrors("No Database Connection");
  2242. +    if (autocommit) db->start_transaction();
  2243. +
  2244. +    for (list<string>::iterator i =_sql.begin(); i!=_sql.end(); i++)
  2245. +    {
  2246. +      query = *i;
  2247. +      Dataset::parse_sql(query);
  2248. +      if ((result = static_cast<MysqlDatabase *>(db)->query_with_reconnect(query.c_str())) != MYSQL_OK)
  2249. +      {
  2250. +        throw DbErrors(db->getErrorMsg());
  2251. +      }
  2252. +    } // end of for
  2253. +
  2254. +    if (db->in_transaction() && autocommit) db->commit_transaction();
  2255. +
  2256. +    active = true;
  2257. +    ds_state = dsSelect;
  2258. +    if (autorefresh)
  2259. +      refresh();
  2260. +  } // end of try
  2261. +  catch(...)
  2262. +  {
  2263. +    if (db->in_transaction()) db->rollback_transaction();
  2264. +    throw;
  2265. +  }
  2266. +
  2267. +}
  2268. +
  2269. +void MysqlDataset::make_insert() {
  2270. +  make_query(insert_sql);
  2271. +  last();
  2272. +}
  2273. +
  2274. +void MysqlDataset::make_edit() {
  2275. +  make_query(update_sql);
  2276. +}
  2277. +
  2278. +
  2279. +void MysqlDataset::make_deletion() {
  2280. +  make_query(delete_sql);
  2281. +}
  2282. +
  2283. +void MysqlDataset::fill_fields() {
  2284. +  if ((db == NULL) || (result.record_header.size() == 0) || (result.records.size() < (unsigned int)frecno)) return;
  2285. +
  2286. +  if (fields_object->size() == 0) // Filling columns name
  2287. +  {
  2288. +    const unsigned int ncols = result.record_header.size();
  2289. +    fields_object->resize(ncols);
  2290. +    for (unsigned int i = 0; i < ncols; i++)
  2291. +      (*fields_object)[i].props = result.record_header[i];
  2292. +  }
  2293. +
  2294. +  //Filling result
  2295. +  if (result.records.size() != 0)
  2296. +  {
  2297. +    const sql_record *row = result.records[frecno];
  2298. +    if (row)
  2299. +    {
  2300. +      const unsigned int ncols = row->size();
  2301. +      fields_object->resize(ncols);
  2302. +      for (unsigned int i = 0; i < ncols; i++)
  2303. +        (*fields_object)[i].val = row->at(i);
  2304. +      return;
  2305. +    }
  2306. +  }
  2307. +  const unsigned int ncols = result.record_header.size();
  2308. +  fields_object->resize(ncols);
  2309. +  for (unsigned int i = 0; i < ncols; i++)
  2310. +    (*fields_object)[i].val = "";
  2311. +}
  2312. +
  2313. +
  2314. +//------------- public functions implementation -----------------//
  2315. +//FILE* file;
  2316. +int MysqlDataset::exec(const string &sql) {
  2317. +  if (!handle()) throw DbErrors("No Database Connection");
  2318. +  string qry = sql;
  2319. +  int res;
  2320. +  exec_res.clear();
  2321. +
  2322. +  // enforce the "auto_increment" keyword to be appended to "integer primary key"
  2323. +  const char* toFind = "integer primary key";
  2324. +  size_t loc = qry.find(toFind);
  2325. +  if (loc != string::npos)
  2326. +  {
  2327. +    qry = qry.insert(loc + strlen(toFind), " auto_increment ");
  2328. +  }
  2329. +
  2330. +  CLog::Log(LOGDEBUG,"Mysql execute: %s", qry.c_str());
  2331. +
  2332. +  if (db->setErr( static_cast<MysqlDatabase *>(db)->query_with_reconnect(qry.c_str()), qry.c_str()) != MYSQL_OK)
  2333. +  {
  2334. +    throw DbErrors(db->getErrorMsg());
  2335. +  }
  2336. +  else
  2337. +  {
  2338. +    // TODO: collect results and store in exec_res
  2339. +
  2340. +
  2341. +    return res;
  2342. +  }
  2343. +}
  2344. +
  2345. +int MysqlDataset::exec() {
  2346. +   return exec(sql);
  2347. +}
  2348. +
  2349. +const void* MysqlDataset::getExecRes() {
  2350. +  return &exec_res;
  2351. +}
  2352. +
  2353. +
  2354. +bool MysqlDataset::query(const char *query) {
  2355. +  if(!handle()) throw DbErrors("No Database Connection");
  2356. +  std::string qry = query;
  2357. +  int fs = qry.find("select");
  2358. +  int fS = qry.find("SELECT");
  2359. +  if (!( fs >= 0 || fS >=0))
  2360. +    throw DbErrors("MUST be select SQL!");
  2361. +
  2362. +  close();
  2363. +
  2364. +  MYSQL_RES *stmt = NULL;
  2365. +
  2366. +  if ( static_cast<MysqlDatabase*>(db)->setErr(static_cast<MysqlDatabase*>(db)->query_with_reconnect(query), query) != MYSQL_OK )
  2367. +    throw DbErrors(db->getErrorMsg());
  2368. +
  2369. +  MYSQL* conn = handle();
  2370. +  stmt = m_MySQL.mysql_store_result(conn);
  2371. +
  2372. +  // column headers
  2373. +  const unsigned int numColumns = m_MySQL.mysql_num_fields(stmt);
  2374. +  MYSQL_FIELD *fields = m_MySQL.mysql_fetch_fields(stmt);
  2375. +  MYSQL_ROW row;
  2376. +  result.record_header.resize(numColumns);
  2377. +  for (unsigned int i = 0; i < numColumns; i++)
  2378. +    result.record_header[i].name = fields[i].name;
  2379. +
  2380. +  // returned rows
  2381. +  while ((row = m_MySQL.mysql_fetch_row(stmt)))
  2382. +  { // have a row of data
  2383. +    sql_record *res = new sql_record;
  2384. +    res->resize(numColumns);
  2385. +    for (unsigned int i = 0; i < numColumns; i++)
  2386. +    {
  2387. +      field_value &v = res->at(i);
  2388. +      switch (fields[i].type)
  2389. +      {
  2390. +      case MYSQL_TYPE_LONGLONG:
  2391. +      case MYSQL_TYPE_DECIMAL:
  2392. +      case MYSQL_TYPE_TINY:
  2393. +      case MYSQL_TYPE_SHORT:
  2394. +      case MYSQL_TYPE_INT24:
  2395. +      case MYSQL_TYPE_LONG:
  2396. +        if (row[i] != NULL)
  2397. +        {
  2398. +          v.set_asInt(atoi(row[i]));
  2399. +        }
  2400. +        else
  2401. +        {
  2402. +          v.set_asInt(0);
  2403. +        }
  2404. +        break;
  2405. +      case MYSQL_TYPE_FLOAT:
  2406. +      case MYSQL_TYPE_DOUBLE:
  2407. +        if (row[i] != NULL)
  2408. +        {
  2409. +          v.set_asDouble(atol(row[i]));
  2410. +        }
  2411. +        else
  2412. +        {
  2413. +          v.set_asDouble(0);
  2414. +        }
  2415. +        break;
  2416. +      case MYSQL_TYPE_STRING:
  2417. +      case MYSQL_TYPE_VAR_STRING:
  2418. +      case MYSQL_TYPE_VARCHAR:
  2419. +        if (row[i] != NULL) v.set_asString((const char *)row[i] );
  2420. +        break;
  2421. +      case MYSQL_TYPE_TINY_BLOB:
  2422. +      case MYSQL_TYPE_MEDIUM_BLOB:
  2423. +      case MYSQL_TYPE_LONG_BLOB:
  2424. +      case MYSQL_TYPE_BLOB:
  2425. +        if (row[i] != NULL) v.set_asString((const char *)row[i]);
  2426. +        break;
  2427. +      case MYSQL_TYPE_NULL:
  2428. +      default:
  2429. +        v.set_asString("");
  2430. +        v.set_isNull();
  2431. +        break;
  2432. +      }
  2433. +    }
  2434. +    result.records.push_back(res);
  2435. +  }
  2436. +  m_MySQL.mysql_free_result(stmt);
  2437. +  active = true;
  2438. +  ds_state = dsSelect;
  2439. +  this->first();
  2440. +  return true;
  2441. +}
  2442. +
  2443. +bool MysqlDataset::query(const string &q) {
  2444. +  return query(q.c_str());
  2445. +}
  2446. +
  2447. +void MysqlDataset::open(const string &sql) {
  2448. +   set_select_sql(sql);
  2449. +   open();
  2450. +}
  2451. +
  2452. +void MysqlDataset::open() {
  2453. +  if (select_sql.size())
  2454. +  {
  2455. +    query(select_sql.c_str());
  2456. +  }
  2457. +  else
  2458. +  {
  2459. +    ds_state = dsInactive;
  2460. +  }
  2461. +}
  2462. +
  2463. +void MysqlDataset::close() {
  2464. +  Dataset::close();
  2465. +  result.clear();
  2466. +  edit_object->clear();
  2467. +  fields_object->clear();
  2468. +  ds_state = dsInactive;
  2469. +  active = false;
  2470. +}
  2471. +
  2472. +
  2473. +void MysqlDataset::cancel() {
  2474. +  if ((ds_state == dsInsert) || (ds_state==dsEdit))
  2475. +  {
  2476. +    if (result.record_header.size())
  2477. +      ds_state = dsSelect;
  2478. +    else
  2479. +      ds_state = dsInactive;
  2480. +  }
  2481. +}
  2482. +
  2483. +
  2484. +int MysqlDataset::num_rows() {
  2485. +  return result.records.size();
  2486. +}
  2487. +
  2488. +
  2489. +bool MysqlDataset::eof() {
  2490. +  return feof;
  2491. +}
  2492. +
  2493. +
  2494. +bool MysqlDataset::bof() {
  2495. +  return fbof;
  2496. +}
  2497. +
  2498. +
  2499. +void MysqlDataset::first() {
  2500. +  Dataset::first();
  2501. +  this->fill_fields();
  2502. +}
  2503. +
  2504. +void MysqlDataset::last() {
  2505. +  Dataset::last();
  2506. +  fill_fields();
  2507. +}
  2508. +
  2509. +void MysqlDataset::prev(void) {
  2510. +  Dataset::prev();
  2511. +  fill_fields();
  2512. +}
  2513. +
  2514. +void MysqlDataset::next(void) {
  2515. +#ifdef _XBOX
  2516. +  free_row();
  2517. +#endif
  2518. +  Dataset::next();
  2519. +  if (!eof())
  2520. +      fill_fields();
  2521. +}
  2522. +
  2523. +void MysqlDataset::free_row(void)
  2524. +{
  2525. +  if (frecno < 0 || (unsigned int)frecno >= result.records.size())
  2526. +    return;
  2527. +
  2528. +  sql_record *row = result.records[frecno];
  2529. +  if (row)
  2530. +  {
  2531. +    delete row;
  2532. +    result.records[frecno] = NULL;
  2533. +  }
  2534. +}
  2535. +
  2536. +bool MysqlDataset::seek(int pos) {
  2537. +  if (ds_state == dsSelect)
  2538. +  {
  2539. +    Dataset::seek(pos);
  2540. +    fill_fields();
  2541. +    return true;
  2542. +  }
  2543. +
  2544. +  return false;
  2545. +}
  2546. +
  2547. +int64_t MysqlDataset::lastinsertid() {
  2548. +  if (!handle()) DbErrors("No Database Connection");
  2549. +  return m_MySQL.mysql_insert_id(handle());
  2550. +}
  2551. +
  2552. +long MysqlDataset::nextid(const char *seq_name) {
  2553. +  if (handle())
  2554. +    return db->nextid(seq_name);
  2555. +
  2556. +  return DB_UNEXPECTED_RESULT;
  2557. +}
  2558. +
  2559. +void MysqlDataset::interrupt() {
  2560. +  // Impossible
  2561. +}
  2562. +
  2563. +}//namespace
  2564. Index: xbmc/lib/sqLite/mysqldataset.h
  2565. ===================================================================
  2566. --- xbmc/lib/sqLite/mysqldataset.h  (revision 0)
  2567. +++ xbmc/lib/sqLite/mysqldataset.h  (working copy)
  2568. @@ -0,0 +1,175 @@
  2569. +/*
  2570. + *      Copyright (C) 2005-2009 Team XBMC
  2571. + *      http://xbmc.org
  2572. + *
  2573. + *  This Program is free software; you can redistribute it and/or modify
  2574. + *  it under the terms of the GNU General Public License as published by
  2575. + *  the Free Software Foundation; either version 2, or (at your option)
  2576. + *  any later version.
  2577. + *
  2578. + *  This Program is distributed in the hope that it will be useful,
  2579. + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  2580. + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2581. + *  GNU General Public License for more details.
  2582. + *
  2583. + *  You should have received a copy of the GNU General Public License
  2584. + *  along with XBMC; see the file COPYING.  If not, write to
  2585. + *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  2586. + *  http://www.gnu.org/copyleft/gpl.html
  2587. + *
  2588. + */
  2589. +
  2590. +#ifndef _MYSQLDATASET_H
  2591. +#define _MYSQLDATASET_H
  2592. +#include <stdio.h>
  2593. +#include "dataset.h"
  2594. +#ifdef _MSC_VER
  2595. +#ifdef _XBOX
  2596. +#include <xtl.h>
  2597. +#include <winsockx.h>
  2598. +#else
  2599. +#include <winsock2.h>
  2600. +#endif
  2601. +#define SHUT_RDWR SD_BOTH
  2602. +#define ETIMEDOUT WSAETIMEDOUT
  2603. +#else
  2604. +#include <netinet/in.h>
  2605. +#include <netinet/tcp.h>
  2606. +#endif
  2607. +#include "DllLibMySQL.h"
  2608. +
  2609. +namespace dbiplus {
  2610. +/***************** Class MysqlDatabase definition ******************
  2611. +
  2612. +       class 'MysqlDatabase' connects with MySQL-server
  2613. +
  2614. +******************************************************************/
  2615. +class MysqlDatabase: public Database {
  2616. +protected:
  2617. +/* connect descriptor */
  2618. +  MYSQL* conn;
  2619. +  bool _in_transaction;
  2620. +  int last_err;
  2621. +  DllLibMySQL m_MySQL;
  2622. +
  2623. +
  2624. +public:
  2625. +/* default constructor */
  2626. +  MysqlDatabase();
  2627. +/* destructor */
  2628. +  ~MysqlDatabase();
  2629. +
  2630. +  Dataset *CreateDataset() const;
  2631. +
  2632. +/* func. returns connection handle with MySQL-server */
  2633. +  MYSQL *getHandle() {  return conn; }
  2634. +/* func. returns current status about MySQL-server connection */
  2635. +  virtual int status();
  2636. +  virtual int setErr(int err_code,const char * qry);
  2637. +/* func. returns error message if error occurs */
  2638. +  virtual const char *getErrorMsg();
  2639. +
  2640. +/* func. connects to database-server */
  2641. +  virtual int connect();
  2642. +/* func. disconnects from database-server */
  2643. +  virtual void disconnect();
  2644. +/* func. creates new database */
  2645. +  virtual int create();
  2646. +/* func. deletes database */
  2647. +  virtual int drop();
  2648. +/* check if database exists (ie has tables/views defined) */
  2649. +  virtual bool exists();
  2650. +
  2651. +  virtual long nextid(const char* seq_name);
  2652. +
  2653. +/* virtual methods for transaction */
  2654. +
  2655. +  virtual void start_transaction();
  2656. +  virtual void commit_transaction();
  2657. +  virtual void rollback_transaction();
  2658. +
  2659. +  bool in_transaction() {return _in_transaction;};
  2660. +  int query_with_reconnect(const char* query);
  2661. +};
  2662. +
  2663. +
  2664. +
  2665. +/***************** Class MysqlDataset definition *******************
  2666. +
  2667. +       class 'MysqlDataset' does a query to MySQL-server
  2668. +
  2669. +******************************************************************/
  2670. +
  2671. +class MysqlDataset : public Dataset {
  2672. +protected:
  2673. +/* query results*/
  2674. +  result_set result;
  2675. +  result_set exec_res;
  2676. +  bool autorefresh;
  2677. +  char* errmsg;
  2678. +  DllLibMySQL m_MySQL;
  2679. +  MYSQL* handle();
  2680. +
  2681. +/* Makes direct queries to database */
  2682. +  virtual void make_query(StringList &_sql);
  2683. +/* Makes direct inserts into database */
  2684. +  virtual void make_insert();
  2685. +/* Edit SQL */
  2686. +  virtual void make_edit();
  2687. +/* Delete SQL */
  2688. +  virtual void make_deletion();
  2689. +
  2690. +
  2691. +/* This function works only with MySQL database
  2692. +  Filling the fields information from select statement */
  2693. +  virtual void fill_fields();
  2694. +/* Changing field values during dataset navigation */
  2695. +  virtual void free_row();  // free the memory allocated for the current row
  2696. +
  2697. +public:
  2698. +/* constructor */
  2699. +  MysqlDataset();
  2700. +  MysqlDataset(MysqlDatabase *newDb);
  2701. +
  2702. +/* destructor */
  2703. +  ~MysqlDataset();
  2704. +
  2705. +/* set autorefresh boolean value (if true - refresh the data after edit()
  2706. +or insert() operations default = false) */
  2707. +  void set_autorefresh(bool val);
  2708. +
  2709. +/* opens a query  & then sets a query results */
  2710. +  virtual void open();
  2711. +  virtual void open(const std::string &sql);
  2712. +/* func. executes a query without results to return */
  2713. +  virtual int  exec ();
  2714. +  virtual int  exec (const std::string &sql);
  2715. +  virtual const void* getExecRes();
  2716. +/* as open, but with our query exept Sql */
  2717. +  virtual bool query(const char *query);
  2718. +  virtual bool query(const std::string &query);
  2719. +/* func. closes a query */
  2720. +  virtual void close(void);
  2721. +/* Cancel changes, made in insert or edit states of dataset */
  2722. +  virtual void cancel();
  2723. +/* last insert id */
  2724. +  virtual int64_t lastinsertid();
  2725. +/* sequence numbers */
  2726. +  virtual long nextid(const char *seq_name);
  2727. +/* sequence numbers */
  2728. +  virtual int num_rows();
  2729. +/* interupt any pending database operation  */
  2730. +  virtual void interrupt();
  2731. +
  2732. +  virtual bool bof();
  2733. +  virtual bool eof();
  2734. +  virtual void first();
  2735. +  virtual void last();
  2736. +  virtual void prev();
  2737. +  virtual void next();
  2738. +/* Go to record No (starting with 0) */
  2739. +  virtual bool seek(int pos=0);
  2740. +
  2741. +};
  2742. +} //namespace
  2743. +#endif
  2744. \ No newline at end of file
  2745. Index: xbmc/lib/sqLite/sqlitedataset.cpp
  2746. ===================================================================
  2747. --- xbmc/lib/sqLite/sqlitedataset.cpp   (revision 30970)
  2748. +++ xbmc/lib/sqLite/sqlitedataset.cpp   (working copy)
  2749. @@ -168,24 +168,57 @@
  2750.  }
  2751.  
  2752.  int SqliteDatabase::connect() {
  2753. -  try {
  2754. +  string db_fullpath;
  2755. +  size_t pos = 0;
  2756. +
  2757. +  // hostname is the relative folder to the database, ensure it's slash terminated
  2758. +  if (host[host.length()-1] != '/' && host[host.length()-1] != '\\')
  2759. +    db_fullpath = host + "/";
  2760. +  else
  2761. +    db_fullpath = host;
  2762. +
  2763. +  // db is the filename for the database, ensure it's not slash prefixed
  2764. +  if (db[0] == '/' || db[0] == '\\')
  2765. +    db_fullpath += db.substr(1);
  2766. +  else
  2767. +    db_fullpath += db;
  2768. +
  2769. +  // ensure the fully qualified path has slashes in the correct direction
  2770. +  if ( (db_fullpath[1] == ':') && string("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz").find(db_fullpath[0]) > 0)
  2771. +  {
  2772. +    while ( (pos = db_fullpath.find("/", pos)) != string::npos )
  2773. +      db_fullpath.replace(pos++, 1, "\\");
  2774. +  }
  2775. +  else
  2776. +  {
  2777. +    while ( (pos = db_fullpath.find("\\", pos)) != string::npos )
  2778. +      db_fullpath.replace(pos++, 1, "/");
  2779. +  }
  2780. +
  2781. +  // ensure the ".db" extension is appended to the end
  2782. +  if ( db_fullpath.find(".db") != (db_fullpath.length()-3) )
  2783. +    db_fullpath += ".db";
  2784. +
  2785. +  try
  2786. +  {
  2787.      disconnect();
  2788. -    if (sqlite3_open(db.c_str(),&conn/*,NULL*/)==SQLITE_OK) {
  2789. -      //cout << "Connected!\n";
  2790. -      sqlite3_busy_handler(conn, busy_callback,NULL);
  2791. +    if (sqlite3_open(db_fullpath.c_str(), &conn)==SQLITE_OK)
  2792. +    {
  2793. +      sqlite3_busy_handler(conn, busy_callback, NULL);
  2794.        char* err=NULL;
  2795. -      if (setErr(sqlite3_exec(getHandle(),"PRAGMA empty_result_callbacks=ON",NULL,NULL,&err),"PRAGMA empty_result_callbacks=ON") != SQLITE_OK) {
  2796. +      if (setErr(sqlite3_exec(getHandle(),"PRAGMA empty_result_callbacks=ON",NULL,NULL,&err),"PRAGMA empty_result_callbacks=ON") != SQLITE_OK)
  2797. +      {
  2798.          throw DbErrors(getErrorMsg());
  2799.        }
  2800.        active = true;
  2801.        return DB_CONNECTION_OK;
  2802.      }
  2803. -    CLog::Log(LOGERROR, "Unable to open database: %s (%lu)", db.c_str(),GetLastError());
  2804. +    CLog::Log(LOGERROR, "unable to open database:%s (%u)", db_fullpath.c_str(), GetLastError());
  2805.      return DB_CONNECTION_NONE;
  2806.    }
  2807.    catch(...)
  2808.    {
  2809. -    CLog::Log(LOGERROR, "Unable to open database: %s (%lu)", db.c_str(),GetLastError());
  2810. +    CLog::Log(LOGERROR, "Unable to open database: %s (%lu)", db_fullpath.c_str(),GetLastError());
  2811.    }
  2812.    return DB_CONNECTION_NONE;
  2813.  }
  2814. Index: xbmc/MusicDatabase.cpp
  2815. ===================================================================
  2816. --- xbmc/MusicDatabase.cpp  (revision 30970)
  2817. +++ xbmc/MusicDatabase.cpp  (working copy)
  2818. @@ -54,7 +54,7 @@
  2819.  using namespace MUSICDATABASEDIRECTORY;
  2820.  using namespace MEDIA_DETECT;
  2821.  
  2822. -#define MUSIC_DATABASE_NAME "MyMusic7.db"
  2823. +#define MUSIC_DATABASE_NAME "MyMusic7"
  2824.  #define RECENTLY_PLAYED_LIMIT 25
  2825.  #define MIN_FULL_SEARCH_LENGTH 3
  2826.  
  2827. @@ -62,7 +62,7 @@
  2828.  
  2829.  CMusicDatabase::CMusicDatabase(void)
  2830.  {
  2831. -  m_strDatabaseFile=MUSIC_DATABASE_NAME;
  2832. +  m_strDefaultDatabaseName=MUSIC_DATABASE_NAME;
  2833.  }
  2834.  
  2835.  CMusicDatabase::~CMusicDatabase(void)
  2836. @@ -70,6 +70,12 @@
  2837.    EmptyCache();
  2838.  }
  2839.  
  2840. +bool CMusicDatabase::Open()
  2841. +{
  2842. +  return CDatabase::Open(g_advancedSettings.m_databaseMusic);
  2843. +}
  2844. +
  2845. +
  2846.  bool CMusicDatabase::CreateTables()
  2847.  {
  2848.    BeginTransaction();
  2849. @@ -78,21 +84,21 @@
  2850.      CDatabase::CreateTables();
  2851.  
  2852.      CLog::Log(LOGINFO, "create artist table");
  2853. -    m_pDS->exec("CREATE TABLE artist ( idArtist integer primary key, strArtist text)\n");
  2854. +    m_pDS->exec("CREATE TABLE artist ( idArtist integer primary key, strArtist varchar(256))\n");
  2855.      CLog::Log(LOGINFO, "create album table");
  2856. -    m_pDS->exec("CREATE TABLE album ( idAlbum integer primary key, strAlbum text, idArtist integer, strExtraArtists text, idGenre integer, strExtraGenres text, iYear integer, idThumb integer)\n");
  2857. +    m_pDS->exec("CREATE TABLE album ( idAlbum integer primary key, strAlbum varchar(256), idArtist integer, strExtraArtists text, idGenre integer, strExtraGenres text, iYear integer, idThumb integer)\n");
  2858.      CLog::Log(LOGINFO, "create genre table");
  2859. -    m_pDS->exec("CREATE TABLE genre ( idGenre integer primary key, strGenre text)\n");
  2860. +    m_pDS->exec("CREATE TABLE genre ( idGenre integer primary key, strGenre varchar(256))\n");
  2861.      CLog::Log(LOGINFO, "create path table");
  2862. -    m_pDS->exec("CREATE TABLE path ( idPath integer primary key, strPath text, strHash text)\n");
  2863. +    m_pDS->exec("CREATE TABLE path ( idPath integer primary key, strPath varchar(512), strHash text)\n");
  2864.      CLog::Log(LOGINFO, "create song table");
  2865. -    m_pDS->exec("CREATE TABLE song ( idSong integer primary key, idAlbum integer, idPath integer, idArtist integer, strExtraArtists text, idGenre integer, strExtraGenres text, strTitle text, iTrack integer, iDuration integer, iYear integer, dwFileNameCRC text, strFileName text, strMusicBrainzTrackID text, strMusicBrainzArtistID text, strMusicBrainzAlbumID text, strMusicBrainzAlbumArtistID text, strMusicBrainzTRMID text, iTimesPlayed integer, iStartOffset integer, iEndOffset integer, idThumb integer, lastplayed text default NULL, rating char default '0', comment text)\n");
  2866. +    m_pDS->exec("CREATE TABLE song ( idSong integer primary key, idAlbum integer, idPath integer, idArtist integer, strExtraArtists text, idGenre integer, strExtraGenres text, strTitle varchar(512), iTrack integer, iDuration integer, iYear integer, dwFileNameCRC text, strFileName text, strMusicBrainzTrackID text, strMusicBrainzArtistID text, strMusicBrainzAlbumID text, strMusicBrainzAlbumArtistID text, strMusicBrainzTRMID text, iTimesPlayed integer, iStartOffset integer, iEndOffset integer, idThumb integer, lastplayed text default NULL, rating char default '0', comment text)\n");
  2867.      CLog::Log(LOGINFO, "create albuminfo table");
  2868.      m_pDS->exec("CREATE TABLE albuminfo ( idAlbumInfo integer primary key, idAlbum integer, iYear integer, idGenre integer, strExtraGenres text, strMoods text, strStyles text, strThemes text, strReview text, strImage text, strLabel text, strType text, iRating integer)\n");
  2869.      CLog::Log(LOGINFO, "create albuminfosong table");
  2870.      m_pDS->exec("CREATE TABLE albuminfosong ( idAlbumInfoSong integer primary key, idAlbumInfo integer, iTrack integer, strTitle text, iDuration integer)\n");
  2871.      CLog::Log(LOGINFO, "create thumb table");
  2872. -    m_pDS->exec("CREATE TABLE thumb (idThumb integer primary key, strThumb text)\n");
  2873. +    m_pDS->exec("CREATE TABLE thumb (idThumb integer primary key, strThumb varchar(256))\n");
  2874.      CLog::Log(LOGINFO, "create artistnfo table");
  2875.      m_pDS->exec("CREATE TABLE artistinfo ( idArtistInfo integer primary key, idArtist integer, strBorn text, strFormed text, strGenres text, strMoods text, strStyles text, strInstruments text, strBiography text, strDied text, strDisbanded text, strYearsActive text, strImage text, strFanart text)\n");
  2876.      CLog::Log(LOGINFO, "create content table");
  2877. @@ -1340,7 +1346,7 @@
  2878.      if (NULL == m_pDS.get()) return false;
  2879.  
  2880.      CStdString strSQL;
  2881. -    strSQL.Format("select distinct albumview.* from song join albumview on albumview.idAlbum=song.idAlbum where song.lastplayed NOT NULL order by song.lastplayed desc limit %i", RECENTLY_PLAYED_LIMIT);
  2882. +    strSQL.Format("select distinct albumview.* from song join albumview on albumview.idAlbum=song.idAlbum where song.lastplayed IS NOT NULL order by song.lastplayed desc limit %i", RECENTLY_PLAYED_LIMIT);
  2883.      CLog::Log(LOGDEBUG, "%s query: %s", __FUNCTION__, strSQL.c_str());
  2884.      if (!m_pDS->query(strSQL.c_str())) return false;
  2885.      int iRowsFound = m_pDS->num_rows();
  2886. @@ -1374,7 +1380,7 @@
  2887.      if (NULL == m_pDS.get()) return false;
  2888.  
  2889.      CStdString strSQL;
  2890. -    strSQL.Format("select * from songview join albumview on (songview.idAlbum = albumview.idAlbum) where albumview.idalbum in (select distinct albumview.idalbum from albumview join song on albumview.idAlbum=song.idAlbum where song.lastplayed NOT NULL order by song.lastplayed desc limit %i)", g_advancedSettings.m_iMusicLibraryRecentlyAddedItems);
  2891. +    strSQL.Format("select * from songview join albumview on (songview.idAlbum = albumview.idAlbum) where albumview.idalbum in (select distinct albumview.idalbum from albumview join song on albumview.idAlbum=song.idAlbum where song.lastplayed IS NOT NULL order by song.lastplayed desc limit %i)", g_advancedSettings.m_iMusicLibraryRecentlyAddedItems);
  2892.      CLog::Log(LOGDEBUG,"GetRecentlyPlayedAlbumSongs() query: %s", strSQL.c_str());
  2893.      if (!m_pDS->query(strSQL.c_str())) return false;
  2894.  
  2895. @@ -1936,7 +1942,7 @@
  2896.      // but we must keep all paths that have been scanned that may contain songs in subpaths
  2897.  
  2898.      // first create a temporary table of song paths
  2899. -    m_pDS->exec("CREATE TEMPORARY TABLE songpaths (idPath integer, strPath)\n");
  2900. +    m_pDS->exec("CREATE TEMPORARY TABLE songpaths (idPath integer, strPath varchar(512))\n");
  2901.      m_pDS->exec("INSERT INTO songpaths select idPath,strPath from path where idPath in (select idPath from song)\n");
  2902.  
  2903.      // grab all paths that aren't immediately connected with a song
  2904. Index: xbmc/MusicDatabase.h
  2905. ===================================================================
  2906. --- xbmc/MusicDatabase.h    (revision 30970)
  2907. +++ xbmc/MusicDatabase.h    (working copy)
  2908. @@ -112,6 +112,7 @@
  2909.  public:
  2910.    CMusicDatabase(void);
  2911.    virtual ~CMusicDatabase(void);
  2912. +  virtual bool Open();
  2913.  
  2914.    virtual bool CommitTransaction();
  2915.    void EmptyCache();
  2916. Index: xbmc/ProgramDatabase.cpp
  2917. ===================================================================
  2918. --- xbmc/ProgramDatabase.cpp    (revision 30970)
  2919. +++ xbmc/ProgramDatabase.cpp    (working copy)
  2920. @@ -32,7 +32,7 @@
  2921.  //********************************************************************************************************************************
  2922.  CProgramDatabase::CProgramDatabase(void)
  2923.  {
  2924. -  m_strDatabaseFile=PROGRAM_DATABASE_NAME;
  2925. +  m_strDefaultDatabaseName=PROGRAM_DATABASE_NAME;
  2926.  }
  2927.  
  2928.  //********************************************************************************************************************************
  2929. @@ -42,6 +42,11 @@
  2930.  }
  2931.  
  2932.  //********************************************************************************************************************************
  2933. +bool CProgramDatabase::Open()
  2934. +{
  2935. +  return CDatabase::Open();
  2936. +}
  2937. +
  2938.  bool CProgramDatabase::CreateTables()
  2939.  {
  2940.  
  2941. Index: xbmc/ProgramDatabase.h
  2942. ===================================================================
  2943. --- xbmc/ProgramDatabase.h  (revision 30970)
  2944. +++ xbmc/ProgramDatabase.h  (working copy)
  2945. @@ -26,13 +26,15 @@
  2946.  #define COMPARE_PERCENTAGE     0.90f // 90%
  2947.  #define COMPARE_PERCENTAGE_MIN 0.50f // 50%
  2948.  
  2949. -#define PROGRAM_DATABASE_NAME "MyPrograms6.db"
  2950. +#define PROGRAM_DATABASE_NAME "MyPrograms6"
  2951.  
  2952.  class CProgramDatabase : public CDatabase
  2953.  {
  2954.  public:
  2955.    CProgramDatabase(void);
  2956.    virtual ~CProgramDatabase(void);
  2957. +  virtual bool Open();
  2958. +
  2959.    bool AddTrainer(int iTitleId, const CStdString& strText);
  2960.    bool RemoveTrainer(const CStdString& strText);
  2961.    bool GetTrainers(unsigned int iTitleId, std::vector<CStdString>& vecTrainers);
  2962. Index: xbmc/VideoDatabase.cpp
  2963. ===================================================================
  2964. --- xbmc/VideoDatabase.cpp  (revision 30970)
  2965. +++ xbmc/VideoDatabase.cpp  (working copy)
  2966. @@ -1,23 +1,23 @@
  2967.  /*
  2968. - *      Copyright (C) 2005-2008 Team XBMC
  2969. - *      http://www.xbmc.org
  2970. - *
  2971. - *  This Program is free software; you can redistribute it and/or modify
  2972. - *  it under the terms of the GNU General Public License as published by
  2973. - *  the Free Software Foundation; either version 2, or (at your option)
  2974. - *  any later version.
  2975. - *
  2976. - *  This Program is distributed in the hope that it will be useful,
  2977. - *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  2978. - *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2979. - *  GNU General Public License for more details.
  2980. - *
  2981. - *  You should have received a copy of the GNU General Public License
  2982. - *  along with XBMC; see the file COPYING.  If not, write to
  2983. - *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  2984. - *  http://www.gnu.org/copyleft/gpl.html
  2985. - *
  2986. - */
  2987. +*      Copyright (C) 2005-2008 Team XBMC
  2988. +*      http://www.xbmc.org
  2989. +*
  2990. +*  This Program is free software; you can redistribute it and/or modify
  2991. +*  it under the terms of the GNU General Public License as published by
  2992. +*  the Free Software Foundation; either version 2, or (at your option)
  2993. +*  any later version.
  2994. +*
  2995. +*  This Program is distributed in the hope that it will be useful,
  2996. +*  but WITHOUT ANY WARRANTY; without even the implied warranty of
  2997. +*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2998. +*  GNU General Public License for more details.
  2999. +*
  3000. +*  You should have received a copy of the GNU General Public License
  3001. +*  along with XBMC; see the file COPYING.  If not, write to
  3002. +*  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  3003. +*  http://www.gnu.org/copyleft/gpl.html
  3004. +*
  3005. +*/
  3006.  
  3007.  #include "stdafx.h"
  3008.  #include "VideoDatabase.h"
  3009. @@ -45,16 +45,35 @@
  3010.  using namespace DIRECTORY;
  3011.  using namespace VIDEO;
  3012.  
  3013. +#define VIDEO_DATABASE_NAME "MyVideos34"
  3014. +#define VIDEO_DATABASE_VIEW_TVSHOW "SELECT tvshow.*,path.strPath AS strPath," \
  3015. +   "counts.totalcount AS totalCount,counts.watchedcount AS watchedCount," \
  3016. +   "counts.totalcount=counts.watchedcount AS watched FROM tvshow " \
  3017. +   "JOIN tvshowlinkpath ON tvshow.idShow=tvshowlinkpath.idShow " \
  3018. +   "JOIN path ON path.idPath=tvshowlinkpath.idPath " \
  3019. +   "LEFT OUTER join (" \
  3020. +   "    SELECT tvshow.idShow AS idShow,count(1) AS totalcount,count(files.playCount) AS watchedcount FROM tvshow " \
  3021. +   "    JOIN tvshowlinkepisode ON tvshow.idShow=tvshowlinkepisode.idShow " \
  3022. +   "    JOIN episode ON episode.idEpisode=tvshowlinkepisode.idEpisode " \
  3023. +   "    JOIN files ON files.idFile=episode.idFile " \
  3024. +   "    GROUP BY tvshow.idShow" \
  3025. +   ") counts ON tvshow.idShow=counts.idShow "
  3026. +
  3027.  //********************************************************************************************************************************
  3028.  CVideoDatabase::CVideoDatabase(void)
  3029.  {
  3030. -  m_strDatabaseFile=GetDefaultDBName();
  3031. +   m_strDefaultDatabaseName=VIDEO_DATABASE_NAME;
  3032.  }
  3033.  
  3034.  //********************************************************************************************************************************
  3035.  CVideoDatabase::~CVideoDatabase(void)
  3036.  {}
  3037.  
  3038. +bool CVideoDatabase::Open()
  3039. +{
  3040. +   return CDatabase::Open(g_advancedSettings.m_databaseVideo);
  3041. +}
  3042. +
  3043.  //********************************************************************************************************************************
  3044.  bool CVideoDatabase::CreateTables()
  3045.  {
  3046. @@ -130,11 +149,11 @@
  3047.      m_pDS->exec("CREATE TABLE actors ( idActor integer primary key, strActor text, strThumb text )\n");
  3048.  
  3049.      CLog::Log(LOGINFO, "create path table");
  3050. -    m_pDS->exec("CREATE TABLE path ( idPath integer primary key, strPath text, strContent text, strScraper text, strHash text, scanRecursive integer, useFolderNames bool, strSettings text, noUpdate bool)\n");
  3051. +       m_pDS->exec("CREATE TABLE path ( idPath integer primary key, strPath varchar(512), strContent text, strScraper text, strHash text, scanRecursive integer, useFolderNames bool, strSettings text, noUpdate bool)\n");
  3052.      m_pDS->exec("CREATE UNIQUE INDEX ix_path ON path ( strPath )\n");
  3053.  
  3054.      CLog::Log(LOGINFO, "create files table");
  3055. -    m_pDS->exec("CREATE TABLE files ( idFile integer primary key, idPath integer, strFilename text, playCount integer, lastPlayed text)\n");
  3056. +       m_pDS->exec("CREATE TABLE files ( idFile integer primary key, idPath integer, strFilename varchar(512), playCount integer, lastPlayed text)\n");
  3057.      m_pDS->exec("CREATE UNIQUE INDEX ix_files ON files ( idPath, strFilename )\n");
  3058.  
  3059.      CLog::Log(LOGINFO, "create tvshow table");
  3060. @@ -142,6 +161,9 @@
  3061.      for (int i = 0; i < VIDEODB_MAX_COLUMNS; i++)
  3062.      {
  3063.        CStdString column;
  3064. +           if ( i == VIDEODB_ID_EPISODE_SEASON || i == VIDEODB_ID_EPISODE_EPISODE || i == VIDEODB_ID_EPISODE_BOOKMARK)
  3065. +               column.Format(",c%02d varchar(24)", i);
  3066. +           else
  3067.        column.Format(",c%02d text", i);
  3068.        columns += column;
  3069.      }
  3070. @@ -263,28 +285,13 @@
  3071.        "strAudioCodec text, iAudioChannels integer, strAudioLanguage text, strSubtitleLanguage text, iVideoDuration integer)");
  3072.      m_pDS->exec("CREATE INDEX ix_streamdetails ON streamdetails (idFile)");
  3073.  
  3074. -    CLog::Log(LOGINFO, "create tvshowview");
  3075. -    CStdString showview=FormatSQL("create view tvshowview as select tvshow.*,path.strPath as strPath,"
  3076. -                                  "counts.totalcount as totalCount,counts.watchedcount as watchedCount,"
  3077. -                                  "counts.totalcount=counts.watchedcount as watched from tvshow "
  3078. -                                  "join tvshowlinkpath on tvshow.idShow=tvshowlinkpath.idShow "
  3079. -                                  "join path on path.idpath=tvshowlinkpath.idPath "
  3080. -                                  "left outer join ("
  3081. -                                  "    select tvshow.idShow as idShow,count(1) as totalcount,count(files.playCount) as watchedcount from tvshow "
  3082. -                                  "    join tvshowlinkepisode on tvshow.idShow = tvshowlinkepisode.idShow "
  3083. -                                  "    join episode on episode.idEpisode = tvshowlinkepisode.idEpisode "
  3084. -                                  "    join files on files.idFile = episode.idFile "
  3085. -                                  "    group by tvshow.idShow"
  3086. -                                  ") counts on tvshow.idShow = counts.idShow");
  3087. -    m_pDS->exec(showview.c_str());
  3088. -
  3089.      CLog::Log(LOGINFO, "create episodeview");
  3090.      CStdString episodeview = FormatSQL("create view episodeview as select episode.*,files.strFileName as strFileName,"
  3091.                                         "path.strPath as strPath,files.playCount as playCount,files.lastPlayed as lastPlayed,tvshow.c%02d as strTitle,tvshow.c%02d as strStudio,tvshow.idShow as idShow,"
  3092.                                         "tvshow.c%02d as premiered, tvshow.c%02d as mpaa from episode "
  3093.                                         "join files on files.idFile=episode.idFile "
  3094. -                                       "join tvshowlinkepisode on episode.idepisode=tvshowlinkepisode.idepisode "
  3095. -                                       "join tvshow on tvshow.idshow=tvshowlinkepisode.idshow "
  3096. +           "join tvshowlinkepisode on episode.idEpisode=tvshowlinkepisode.idEpisode "
  3097. +           "join tvshow on tvshow.idShow=tvshowlinkepisode.idShow "
  3098.                                         "join path on files.idPath=path.idPath",VIDEODB_ID_TV_TITLE, VIDEODB_ID_TV_STUDIOS, VIDEODB_ID_TV_PREMIERED, VIDEODB_ID_TV_MPAA);
  3099.      m_pDS->exec(episodeview.c_str());
  3100.  
  3101. @@ -383,7 +390,7 @@
  3102.      // then grab all tvshow paths
  3103.      if (!m_pDS->query("select strPath,scanRecursive,useFolderNames,strContent,noUpdate from path"
  3104.                        " where ( strContent = 'tvshows'"
  3105. -                      "       or idPath in (select idpath from tvshowlinkpath))"
  3106. +           "       or idPath in (select idPath from tvshowlinkpath))"
  3107.                        " and strPath NOT like 'multipath://%%'"
  3108.                        " order by strPath"))
  3109.        return false;
  3110. @@ -419,8 +426,8 @@
  3111.      // not making mistakes must take priority
  3112.      if (!m_pDS->query("select strPath,noUpdate from path"
  3113.                         " where idPath in (select idPath from files join movie on movie.idFile=files.idFile)"
  3114. -                       " and idPath NOT in (select idpath from tvshowlinkpath)"
  3115. -                       " and idPath NOT in (select idpath from files where strFileName like 'video_ts.ifo')" // dvdfolders get stacked to a single item in parent folder
  3116. +           " and idPath NOT in (select idPath from tvshowlinkpath)"
  3117. +           " and idPath NOT in (select idPath from files where strFileName like 'video_ts.ifo')" // dvdfolders get stacked to a single item in parent folder
  3118.                         " and strPath NOT like 'multipath://%%'"
  3119.                         " and strContent NOT in ('movies', 'tvshows', 'None')" // these have been added above
  3120.                         " order by strPath"))
  3121. @@ -457,7 +464,7 @@
  3122.    {
  3123.      if (NULL == m_pDB.get()) return false;
  3124.      if (NULL == m_pDS.get()) return false;
  3125. -    strSQL = FormatSQL("select distinct path.idPath from path,tvshowlinkepisode join episode on tvshowlinkepisode.idEpisode=episode.idEpisode join files on files.idPath=path.idPath where episode.idFile = files.idFile and tvshowlinkepisode.idShow=%i",idShow);
  3126. +       strSQL = FormatSQL("SELECT DISTINCT idPath FROM files JOIN episode ON episode.idFile=files.idFile JOIN tvshowlinkepisode ON tvshowlinkepisode.idEpisode=episode.idEpisode WHERE tvshowlinkepisode.idShow=%i",idShow);
  3127.      m_pDS->query(strSQL.c_str());
  3128.      while (!m_pDS->eof())
  3129.      {
  3130. @@ -750,7 +757,7 @@
  3131.  
  3132.      CStdString strSQL;
  3133.      if (idFile == -1)
  3134. -      strSQL=FormatSQL("select idMovie from movie join files on files.idFile=movie.idFile where files.idpath = %i",idPath);
  3135. +           strSQL=FormatSQL("select idMovie from movie join files on files.idFile=movie.idFile where files.idPath=%i",idPath);
  3136.      else
  3137.        strSQL=FormatSQL("select idMovie from movie where idFile=%i", idFile);
  3138.  
  3139. @@ -794,7 +801,7 @@
  3140.  
  3141.      while (iFound == 0 && CUtil::GetParentPath(strPath1, strParent))
  3142.      {
  3143. -      strSQL=FormatSQL("select idShow from path,tvshowlinkpath where tvshowlinkpath.idpath = path.idpath and strPath like '%s'",strParent.c_str());
  3144. +           strSQL=FormatSQL("select idShow from path,tvshowlinkpath where tvshowlinkpath.idPath=path.idPath and strPath like '%s'",strParent.c_str());
  3145.        m_pDS->query(strSQL.c_str());
  3146.        if (!m_pDS->eof())
  3147.        {
  3148. @@ -920,7 +927,7 @@
  3149.        CStdString strSQL=FormatSQL("insert into movie (idMovie, idFile) values (NULL, %i)", idFile);
  3150.        m_pDS->exec(strSQL.c_str());
  3151.        idMovie = (int)m_pDS->lastinsertid();
  3152. -//      CommitTransaction();
  3153. +           //      CommitTransaction();
  3154.      }
  3155.  
  3156.      return idMovie;
  3157. @@ -939,7 +946,7 @@
  3158.      if (NULL == m_pDB.get()) return -1;
  3159.      if (NULL == m_pDS.get()) return -1;
  3160.  
  3161. -    CStdString strSQL=FormatSQL("select tvshowlinkpath.idShow from path,tvshowlinkpath where path.strPath like '%s' and path.idPath = tvshowlinkpath.idPath",strPath.c_str());
  3162. +       CStdString strSQL=FormatSQL("select tvshowlinkpath.idShow from path,tvshowlinkpath where path.strPath like '%s' and path.idPath=tvshowlinkpath.idPath",strPath.c_str());
  3163.      m_pDS->query(strSQL.c_str());
  3164.      if (m_pDS->num_rows() != 0)
  3165.        return m_pDS->fv("tvshowlinkpath.idShow").get_asInt();
  3166. @@ -954,7 +961,7 @@
  3167.      strSQL=FormatSQL("insert into tvshowlinkpath values (%i,%i)",idTvShow,idPath);
  3168.      m_pDS->exec(strSQL.c_str());
  3169.  
  3170. -//    CommitTransaction();
  3171. +       //    CommitTransaction();
  3172.  
  3173.      return idTvShow;
  3174.    }
  3175. @@ -983,7 +990,7 @@
  3176.  
  3177.      strSQL=FormatSQL("insert into tvshowlinkepisode (idShow,idEpisode) values (%i,%i)",idShow,idEpisode);
  3178.      m_pDS->exec(strSQL.c_str());
  3179. -//    CommitTransaction();
  3180. +       //    CommitTransaction();
  3181.  
  3182.      return idEpisode;
  3183.    }
  3184. @@ -1370,16 +1377,16 @@
  3185.      DeleteThumbForItem(strPath,true);
  3186.  
  3187.      CStdString strSQL;
  3188. -    strSQL=FormatSQL("delete from genrelinktvshow where idshow=%i", idTvShow);
  3189. +       strSQL=FormatSQL("delete from genrelinktvshow where idShow=%i", idTvShow);
  3190.      m_pDS->exec(strSQL.c_str());
  3191.  
  3192. -    strSQL=FormatSQL("delete from actorlinktvshow where idshow=%i", idTvShow);
  3193. +       strSQL=FormatSQL("delete from actorlinktvshow where idShow=%i", idTvShow);
  3194.      m_pDS->exec(strSQL.c_str());
  3195.  
  3196. -    strSQL=FormatSQL("delete from directorlinktvshow where idshow=%i", idTvShow);
  3197. +       strSQL=FormatSQL("delete from directorlinktvshow where idShow=%i", idTvShow);
  3198.      m_pDS->exec(strSQL.c_str());
  3199.  
  3200. -    strSQL=FormatSQL("delete from studiolinktvshow where idshow=%i", idTvShow);
  3201. +       strSQL=FormatSQL("delete from studiolinktvshow where idShow=%i", idTvShow);
  3202.      m_pDS->exec(strSQL.c_str());
  3203.  
  3204.      // remove all info other than the id
  3205. @@ -1405,23 +1412,23 @@
  3206.  void CVideoDatabase::GetMoviesByActor(const CStdString& strActor, CFileItemList& items)
  3207.  {
  3208.    CStdString where;
  3209. -  where.Format("join actorlinkmovie on actorlinkmovie.idmovie=movieview.idmovie join actors on actors.idActor=actorlinkmovie.idActor where actors.stractor='%s'", strActor.c_str());
  3210. +   where.Format("join actorlinkmovie on actorlinkmovie.idMovie=movieview.idMovie join actors on actors.idActor=actorlinkmovie.idActor where actors.strActor='%s'", strActor.c_str());
  3211.    GetMoviesByWhere("videodb://1/2/", where, "", items);
  3212.  }
  3213.  
  3214.  void CVideoDatabase::GetTvShowsByActor(const CStdString& strActor, CFileItemList& items)
  3215.  {
  3216. -  CStdString where = FormatSQL("join actorlinktvshow on actorlinktvshow.idshow=tvshowview.idshow "
  3217. +   CStdString where = FormatSQL("join actorlinktvshow on actorlinktvshow.idShow=tvshowview.idShow "
  3218.                                 "join actors on actors.idActor=actorlinktvshow.idActor "
  3219. -                               "where actors.stractor='%s'", strActor.c_str());
  3220. +       "where actors.strActor='%s'", strActor.c_str());
  3221.    GetTvShowsByWhere("videodb://2/2/", where, items);
  3222.  }
  3223.  
  3224.  void CVideoDatabase::GetEpisodesByActor(const CStdString& strActor, CFileItemList& items)
  3225.  {
  3226. -  CStdString where = FormatSQL("join actorlinkepisode on actorlinkepisode.idepisode=episodeview.idepisode "
  3227. +   CStdString where = FormatSQL("join actorlinkepisode on actorlinkepisode.idEpisode=episodeview.idEpisode "
  3228.                                 "join actors on actors.idActor=actorlinkepisode.idActor "
  3229. -                               "where actors.stractor='%s'", strActor.c_str());
  3230. +       "where actors.strActor='%s'", strActor.c_str());
  3231.    GetEpisodesByWhere("videodb://2/2/", where, items);
  3232.  }
  3233.  
  3234. @@ -1435,9 +1442,9 @@
  3235.  
  3236.      CStdString strSQL;
  3237.      if (strArtist.IsEmpty())  // TODO: SMARTPLAYLISTS what is this here for???
  3238. -      strSQL=FormatSQL("select distinct * from musicvideoview join artistlinkmusicvideo on artistlinkmusicvideo.idmvideo=musicvideoview.idmvideo join actors on actors.idActor=artistlinkmusicvideo.idArtist");
  3239. +           strSQL=FormatSQL("select distinct * from musicvideoview join artistlinkmusicvideo on artistlinkmusicvideo.idMVideo=musicvideoview.idMVideo join actors on actors.idActor=artistlinkmusicvideo.idArtist");
  3240.      else
  3241. -      strSQL=FormatSQL("select * from musicvideoview join artistlinkmusicvideo on artistlinkmusicvideo.idmvideo=musicvideoview.idmvideo join actors on actors.idActor=artistlinkmusicvideo.idArtist where actors.stractor='%s'", strArtist.c_str());
  3242. +           strSQL=FormatSQL("select * from musicvideoview join artistlinkmusicvideo on artistlinkmusicvideo.idMVideo=musicvideoview.idMVideo join actors on actors.idActor=artistlinkmusicvideo.idArtist where actors.strActor='%s'", strArtist.c_str());
  3243.      m_pDS->query( strSQL.c_str() );
  3244.  
  3245.      while (!m_pDS->eof())
  3246. @@ -1486,7 +1493,7 @@
  3247.        idTvShow = GetTvShowId(strPath);
  3248.      if (idTvShow < 0) return ;
  3249.  
  3250. -    CStdString sql = FormatSQL("select * from tvshowview where idshow=%i", idTvShow);
  3251. +       CStdString sql = FormatSQL(VIDEO_DATABASE_VIEW_TVSHOW " where idShow=%i", idTvShow);
  3252.      if (!m_pDS->query(sql.c_str()))
  3253.        return;
  3254.      details = GetDetailsForTvShow(m_pDS, true);
  3255. @@ -1506,7 +1513,7 @@
  3256.        idEpisode = GetEpisodeId(strFilenameAndPath);
  3257.      if (idEpisode < 0) return false;
  3258.  
  3259. -    CStdString sql = FormatSQL("select * from episodeview where idepisode=%i",idEpisode);
  3260. +       CStdString sql = FormatSQL("select * from episodeview where idEpisode=%i",idEpisode);
  3261.      if (!m_pDS->query(sql.c_str()))
  3262.        return false;
  3263.      details = GetDetailsForEpisode(m_pDS, true);
  3264. @@ -1528,7 +1535,7 @@
  3265.        idMVideo = GetMusicVideoId(strFilenameAndPath);
  3266.      if (idMVideo < 0) return ;
  3267.  
  3268. -    CStdString sql = FormatSQL("select * from musicvideoview where idmvideo=%i", idMVideo);
  3269. +       CStdString sql = FormatSQL("select * from musicvideoview where idMVideo=%i", idMVideo);
  3270.      if (!m_pDS->query(sql.c_str()))
  3271.        return;
  3272.      details = GetDetailsForMusicVideo(m_pDS);
  3273. @@ -1685,7 +1692,7 @@
  3274.          AddSetToMovie(idMovie, idSet);
  3275.        }
  3276.      }
  3277. -    
  3278. +
  3279.      if (details.HasStreamDetails())
  3280.        SetStreamDetailsForFileId(details.m_streamDetails, GetFileId(strFilenameAndPath));
  3281.  
  3282. @@ -1975,9 +1982,9 @@
  3283.      if (iType == VIDEODB_CONTENT_EPISODES)
  3284.        strSQL=FormatSQL("select path.strPath,files.strFileName from path, files, episode where path.idPath=files.idPath and files.idFile=episode.idFile and episode.idEpisode=%i order by strFilename", idMovie );
  3285.      if (iType == VIDEODB_CONTENT_TVSHOWS)
  3286. -      strSQL=FormatSQL("select path.strPath from path,tvshowlinkpath where path.idpath=tvshowlinkpath.idpath and tvshowlinkpath.idshow=%i", idMovie );
  3287. +           strSQL=FormatSQL("select path.strPath from path,tvshowlinkpath where path.idPath=tvshowlinkpath.idPath and tvshowlinkpath.idShow=%i", idMovie );
  3288.      if (iType ==VIDEODB_CONTENT_MUSICVIDEOS)
  3289. -      strSQL=FormatSQL("select path.strPath,files.strFileName from path, files, musicvideo where path.idPath=files.idPath and files.idFile=musicvideo.idFile and musicvideo.idmvideo=%i order by strFilename", idMovie );
  3290. +           strSQL=FormatSQL("select path.strPath,files.strFileName from path, files, musicvideo where path.idPath=files.idPath and files.idFile=musicvideo.idFile and musicvideo.idMVideo=%i order by strFilename", idMovie );
  3291.  
  3292.      m_pDS->query( strSQL.c_str() );
  3293.      if (!m_pDS->eof())
  3294. @@ -2281,19 +2288,19 @@
  3295.      BeginTransaction();
  3296.  
  3297.      CStdString strSQL;
  3298. -    strSQL=FormatSQL("delete from genrelinkmovie where idmovie=%i", idMovie);
  3299. +       strSQL=FormatSQL("delete from genrelinkmovie where idMovie=%i", idMovie);
  3300.      m_pDS->exec(strSQL.c_str());
  3301.  
  3302. -    strSQL=FormatSQL("delete from actorlinkmovie where idmovie=%i", idMovie);
  3303. +       strSQL=FormatSQL("delete from actorlinkmovie where idMovie=%i", idMovie);
  3304.      m_pDS->exec(strSQL.c_str());
  3305.  
  3306. -    strSQL=FormatSQL("delete from directorlinkmovie where idmovie=%i", idMovie);
  3307. +       strSQL=FormatSQL("delete from directorlinkmovie where idMovie=%i", idMovie);
  3308.      m_pDS->exec(strSQL.c_str());
  3309.  
  3310. -    strSQL=FormatSQL("delete from studiolinkmovie where idmovie=%i", idMovie);
  3311. +       strSQL=FormatSQL("delete from studiolinkmovie where idMovie=%i", idMovie);
  3312.      m_pDS->exec(strSQL.c_str());
  3313.  
  3314. -    strSQL=FormatSQL("delete from setlinkmovie where idmovie=%i", idMovie);
  3315. +       strSQL=FormatSQL("delete from setlinkmovie where idMovie=%i", idMovie);
  3316.      m_pDS->exec(strSQL.c_str());
  3317.  
  3318.      if (!bKeepThumb)
  3319. @@ -2308,10 +2315,10 @@
  3320.      {
  3321.        ClearBookMarksOfFile(strFilenameAndPath);
  3322.  
  3323. -      strSQL=FormatSQL("delete from movie where idmovie=%i", idMovie);
  3324. +           strSQL=FormatSQL("delete from movie where idMovie=%i", idMovie);
  3325.        m_pDS->exec(strSQL.c_str());
  3326.  
  3327. -      strSQL=FormatSQL("delete from movielinktvshow where idmovie=%i", idMovie);
  3328. +           strSQL=FormatSQL("delete from movielinktvshow where idMovie=%i", idMovie);
  3329.        m_pDS->exec(strSQL.c_str());
  3330.      }
  3331.      /*
  3332. @@ -2319,7 +2326,7 @@
  3333.      else
  3334.      {
  3335.        // clear the title
  3336. -      strSQL=FormatSQL("update movie set c%02d=NULL where idmovie=%i", VIDEODB_ID_TITLE, idMovie);
  3337. +       strSQL=FormatSQL("update movie set c%02d=NULL where idMovie=%i", VIDEODB_ID_TITLE, idMovie);
  3338.        m_pDS->exec(strSQL.c_str());
  3339.      }
  3340.      */
  3341. @@ -2350,7 +2357,7 @@
  3342.  
  3343.      BeginTransaction();
  3344.  
  3345. -    CStdString strSQL=FormatSQL("select tvshowlinkepisode.idepisode,path.strPath,files.strFileName from tvshowlinkepisode,path,files,episode where tvshowlinkepisode.idshow=%i and tvshowlinkepisode.idepisode=episode.idEpisode and episode.idFile=files.idFile and files.idPath=path.idPath",idTvShow);
  3346. +       CStdString strSQL=FormatSQL("select tvshowlinkepisode.idEpisode,path.strPath,files.strFileName from tvshowlinkepisode,path,files,episode where tvshowlinkepisode.idShow=%i and tvshowlinkepisode.idEpisode=episode.idEpisode and episode.idFile=files.idFile and files.idPath=path.idPath",idTvShow);
  3347.      m_pDS2->query(strSQL.c_str());
  3348.      while (!m_pDS2->eof())
  3349.      {
  3350. @@ -2362,19 +2369,19 @@
  3351.        m_pDS2->next();
  3352.      }
  3353.  
  3354. -    strSQL=FormatSQL("delete from genrelinktvshow where idshow=%i", idTvShow);
  3355. +       strSQL=FormatSQL("delete from genrelinktvshow where idShow=%i", idTvShow);
  3356.      m_pDS->exec(strSQL.c_str());
  3357.  
  3358. -    strSQL=FormatSQL("delete from actorlinktvshow where idshow=%i", idTvShow);
  3359. +       strSQL=FormatSQL("delete from actorlinktvshow where idShow=%i", idTvShow);
  3360.      m_pDS->exec(strSQL.c_str());
  3361.  
  3362. -    strSQL=FormatSQL("delete from directorlinktvshow where idshow=%i", idTvShow);
  3363. +       strSQL=FormatSQL("delete from directorlinktvshow where idShow=%i", idTvShow);
  3364.      m_pDS->exec(strSQL.c_str());
  3365.  
  3366. -    strSQL=FormatSQL("delete from tvshowlinkpath where idshow=%i", idTvShow);
  3367. +       strSQL=FormatSQL("delete from tvshowlinkpath where idShow=%i", idTvShow);
  3368.      m_pDS->exec(strSQL.c_str());
  3369.  
  3370. -    strSQL=FormatSQL("delete from studiolinktvshow where idshow=%i", idTvShow);
  3371. +       strSQL=FormatSQL("delete from studiolinktvshow where idShow=%i", idTvShow);
  3372.      m_pDS->exec(strSQL.c_str());
  3373.  
  3374.      if (!bKeepThumb)
  3375. @@ -2383,10 +2390,10 @@
  3376.      // keep tvshow table and movielink table so we can update data in place
  3377.      if (!bKeepId)
  3378.      {
  3379. -      strSQL=FormatSQL("delete from tvshow where idshow=%i", idTvShow);
  3380. +           strSQL=FormatSQL("delete from tvshow where idShow=%i", idTvShow);
  3381.        m_pDS->exec(strSQL.c_str());
  3382.  
  3383. -      strSQL=FormatSQL("delete from movielinktvshow where idshow=%i", idTvShow);
  3384. +           strSQL=FormatSQL("delete from movielinktvshow where idShow=%i", idTvShow);
  3385.        m_pDS->exec(strSQL.c_str());
  3386.      }
  3387.  
  3388. @@ -2416,16 +2423,16 @@
  3389.      }
  3390.  
  3391.      CStdString strSQL;
  3392. -    strSQL=FormatSQL("delete from actorlinkepisode where idepisode=%i", idEpisode);
  3393. +       strSQL=FormatSQL("delete from actorlinkepisode where idEpisode=%i", idEpisode);
  3394.      m_pDS->exec(strSQL.c_str());
  3395.  
  3396. -    strSQL=FormatSQL("delete from directorlinkepisode where idepisode=%i", idEpisode);
  3397. +       strSQL=FormatSQL("delete from directorlinkepisode where idEpisode=%i", idEpisode);
  3398.      m_pDS->exec(strSQL.c_str());
  3399.  
  3400. -    strSQL=FormatSQL("select tvshowlinkepisode.idshow from tvshowlinkepisode where idepisode=%i",idEpisode);
  3401. +       strSQL=FormatSQL("select tvshowlinkepisode.idShow from tvshowlinkepisode where idEpisode=%i",idEpisode);
  3402.      m_pDS->query(strSQL.c_str());
  3403.  
  3404. -    strSQL=FormatSQL("delete from tvshowlinkepisode where idepisode=%i", idEpisode);
  3405. +       strSQL=FormatSQL("delete from tvshowlinkepisode where idEpisode=%i", idEpisode);
  3406.      m_pDS->exec(strSQL.c_str());
  3407.  
  3408.      if (!bKeepThumb)
  3409. @@ -2465,16 +2472,16 @@
  3410.      BeginTransaction();
  3411.  
  3412.      CStdString strSQL;
  3413. -    strSQL=FormatSQL("delete from genrelinkmusicvideo where idmvideo=%i", idMVideo);
  3414. +       strSQL=FormatSQL("delete from genrelinkmusicvideo where idMVideo=%i", idMVideo);
  3415.      m_pDS->exec(strSQL.c_str());
  3416.  
  3417. -    strSQL=FormatSQL("delete from artistlinkmusicvideo where idmvideo=%i", idMVideo);
  3418. +       strSQL=FormatSQL("delete from artistlinkmusicvideo where idMVideo=%i", idMVideo);
  3419.      m_pDS->exec(strSQL.c_str());
  3420.  
  3421. -    strSQL=FormatSQL("delete from directorlinkmusicvideo where idmvideo=%i", idMVideo);
  3422. +       strSQL=FormatSQL("delete from directorlinkmusicvideo where idMVideo=%i", idMVideo);
  3423.      m_pDS->exec(strSQL.c_str());
  3424.  
  3425. -    strSQL=FormatSQL("delete from studiolinkmusicvideo where idmvideo=%i", idMVideo);
  3426. +       strSQL=FormatSQL("delete from studiolinkmusicvideo where idMVideo=%i", idMVideo);
  3427.      m_pDS->exec(strSQL.c_str());
  3428.  
  3429.      if (!bKeepThumb)
  3430. @@ -2488,7 +2495,7 @@
  3431.      {
  3432.        ClearBookMarksOfFile(strFilenameAndPath);
  3433.  
  3434. -      strSQL=FormatSQL("delete from musicvideo where idmvideo=%i", idMVideo);
  3435. +           strSQL=FormatSQL("delete from musicvideo where idMVideo=%i", idMVideo);
  3436.        m_pDS->exec(strSQL.c_str());
  3437.      }
  3438.      /*
  3439. @@ -2496,7 +2503,7 @@
  3440.      else
  3441.      {
  3442.        // clear the title
  3443. -      strSQL=FormatSQL("update musicvideo set c%02d=NULL where idmvideo=%i", VIDEODB_ID_MUSICVIDEO_TITLE, idMVideo);
  3444. +       strSQL=FormatSQL("update musicvideo set c%02d=NULL where idMVideo=%i", VIDEODB_ID_MUSICVIDEO_TITLE, idMVideo);
  3445.        m_pDS->exec(strSQL.c_str());
  3446.      }
  3447.      */
  3448. @@ -2860,7 +2867,7 @@
  3449.      if (NULL == m_pDS.get()) return false;
  3450.      CStdString strPath, strFileName;
  3451.      CUtil::Split(strFilenameAndPath, strPath, strFileName);
  3452. -    CStdString strSQL=FormatSQL("select * from settings, files, path where settings.idfile=files.idfile and path.idpath=files.idpath and path.strPath like '%s' and files.strFileName like '%s'", strPath.c_str() , strFileName.c_str());
  3453. +       CStdString strSQL=FormatSQL("select * from settings, files, path where settings.idFile=files.idFile and path.idPath=files.idPath and path.strPath like '%s' and files.strFileName like '%s'", strPath.c_str() , strFileName.c_str());
  3454.  #else
  3455.      int idFile = GetFileId(strFilenameAndPath);
  3456.      if (idFile < 0) return false;
  3457. @@ -3364,7 +3371,7 @@
  3458.                                      "counts.totalcount as totalCount,counts.watchedcount as watchedCount,"
  3459.                                      "counts.totalcount=counts.watchedcount as watched from tvshow "
  3460.                                      "join tvshowlinkpath on tvshow.idShow=tvshowlinkpath.idShow "
  3461. -                                    "join path on path.idpath=tvshowlinkpath.idPath "
  3462. +               "join path on path.idPath=tvshowlinkpath.idPath "
  3463.                                      "left outer join ("
  3464.                                      "    select tvshow.idShow as idShow,count(1) as totalcount,count(episode.c%02d) as watchedcount from tvshow "
  3465.                                      "    join tvshowlinkepisode on tvshow.idShow = tvshowlinkepisode.idShow "
  3466. @@ -3376,8 +3383,8 @@
  3467.                                           "path.strPath as strPath,tvshow.c%02d as strTitle,tvshow.idShow as idShow,"
  3468.                                           "tvshow.c%02d as premiered from episode "
  3469.                                           "join files on files.idFile=episode.idFile "
  3470. -                                         "join tvshowlinkepisode on episode.idepisode=tvshowlinkepisode.idepisode "
  3471. -                                         "join tvshow on tvshow.idshow=tvshowlinkepisode.idshow "
  3472. +               "join tvshowlinkepisode on episode.idEpisode=tvshowlinkepisode.idEpisode "
  3473. +               "join tvshow on tvshow.idShow=tvshowlinkepisode.idShow "
  3474.                                           "join path on files.idPath=path.idPath",VIDEODB_ID_TV_TITLE, VIDEODB_ID_TV_PREMIERED);
  3475.        m_pDS->exec(episodeview.c_str());
  3476.      }
  3477. @@ -3480,8 +3487,8 @@
  3478.                                           "path.strPath as strPath,files.playCount as playCount,files.lastPlayed as lastPlayed,tvshow.c%02d as strTitle,tvshow.idShow as idShow,"
  3479.                                           "tvshow.c%02d as premiered from episode "
  3480.                                           "join files on files.idFile=episode.idFile "
  3481. -                                         "join tvshowlinkepisode on episode.idepisode=tvshowlinkepisode.idepisode "
  3482. -                                         "join tvshow on tvshow.idshow=tvshowlinkepisode.idshow "
  3483. +               "join tvshowlinkepisode on episode.idEpisode=tvshowlinkepisode.idEpisode "
  3484. +               "join tvshow on tvshow.idShow=tvshowlinkepisode.idShow "
  3485.                                           "join path on files.idPath=path.idPath",VIDEODB_ID_TV_TITLE, VIDEODB_ID_TV_PREMIERED);
  3486.        m_pDS->exec(episodeview.c_str());
  3487.        m_pDS->exec("drop view tvshowview");
  3488. @@ -3489,7 +3496,7 @@
  3489.                                      "counts.totalcount as totalCount,counts.watchedcount as watchedCount,"
  3490.                                      "counts.totalcount=counts.watchedcount as watched from tvshow "
  3491.                                      "join tvshowlinkpath on tvshow.idShow=tvshowlinkpath.idShow "
  3492. -                                    "join path on path.idpath=tvshowlinkpath.idPath "
  3493. +               "join path on path.idPath=tvshowlinkpath.idPath "
  3494.                                      "left outer join ("
  3495.                                      "    select tvshow.idShow as idShow,count(1) as totalcount,count(files.playCount) as watchedcount from tvshow "
  3496.                                      "    join tvshowlinkepisode on tvshow.idShow = tvshowlinkepisode.idShow "
  3497. @@ -3536,8 +3543,8 @@
  3498.                                           "path.strPath as strPath,files.playCount as playCount,files.lastPlayed as lastPlayed,tvshow.c%02d as strTitle,tvshow.c%02d as strStudio,tvshow.idShow as idShow,"
  3499.                                           "tvshow.c%02d as premiered from episode "
  3500.                                           "join files on files.idFile=episode.idFile "
  3501. -                                         "join tvshowlinkepisode on episode.idepisode=tvshowlinkepisode.idepisode "
  3502. -                                         "join tvshow on tvshow.idshow=tvshowlinkepisode.idshow "
  3503. +               "join tvshowlinkepisode on episode.idEpisode=tvshowlinkepisode.idEpisode "
  3504. +               "join tvshow on tvshow.idShow=tvshowlinkepisode.idShow "
  3505.                                           "join path on files.idPath=path.idPath",VIDEODB_ID_TV_TITLE, VIDEODB_ID_TV_STUDIOS, VIDEODB_ID_TV_PREMIERED);
  3506.        m_pDS->exec(episodeview.c_str());
  3507.      }
  3508. @@ -3558,14 +3565,14 @@
  3509.                                         "path.strPath as strPath,files.playCount as playCount,files.lastPlayed as lastPlayed,tvshow.c%02d as strTitle,tvshow.c%02d as strStudio,tvshow.idShow as idShow,"
  3510.                                         "tvshow.c%02d as premiered, tvshow.c%02d as mpaa from episode "
  3511.                                         "join files on files.idFile=episode.idFile "
  3512. -                                       "join tvshowlinkepisode on episode.idepisode=tvshowlinkepisode.idepisode "
  3513. -                                       "join tvshow on tvshow.idshow=tvshowlinkepisode.idshow "
  3514. +               "join tvshowlinkepisode on episode.idEpisode=tvshowlinkepisode.idEpisode "
  3515. +               "join tvshow on tvshow.idShow=tvshowlinkepisode.idShow "
  3516.                                         "join path on files.idPath=path.idPath",VIDEODB_ID_TV_TITLE, VIDEODB_ID_TV_STUDIOS, VIDEODB_ID_TV_PREMIERED, VIDEODB_ID_TV_MPAA);
  3517.        m_pDS->exec(episodeview.c_str());
  3518.      }
  3519.      if (iVersion < 31)
  3520.      {
  3521. -      const char* tag1[] = {"idmovie","idshow","idepisode","idmvideo","idactor"};
  3522. +           const char* tag1[] = {"idMovie","idShow","idEpisode","idMVideo","idActor"};
  3523.        const char* tag2[] = {"c08","c06","c06","c02","strThumb"};
  3524.        const char* tag3[] = {"movie","tvshow","episode","musicvideo","actors"};
  3525.        for (int i=0;i<5;++i)
  3526. @@ -3614,7 +3621,7 @@
  3527.        m_pDS->exec("CREATE UNIQUE INDEX ix_setlinkmovie_1 ON setlinkmovie ( idSet, idMovie)\n");
  3528.        m_pDS->exec("CREATE UNIQUE INDEX ix_setlinkmovie_2 ON setlinkmovie ( idMovie, idSet)\n");
  3529.      }
  3530. -    
  3531. +
  3532.      if (iVersion < 34)
  3533.      {
  3534.        m_pDS->exec("DELETE FROM streamdetails");
  3535. @@ -3677,9 +3684,9 @@
  3536.  
  3537.    CStdString exec;
  3538.    if (type == VIDEODB_CONTENT_TVSHOWS)
  3539. -    exec = FormatSQL("UPDATE tvshow set c%02d='%s' WHERE idshow=%i", VIDEODB_ID_TV_FANART, item.GetVideoInfoTag()->m_fanart.m_xml.c_str(), item.GetVideoInfoTag()->m_iDbId);
  3540. +       exec = FormatSQL("UPDATE tvshow set c%02d='%s' WHERE idShow=%i", VIDEODB_ID_TV_FANART, item.GetVideoInfoTag()->m_fanart.m_xml.c_str(), item.GetVideoInfoTag()->m_iDbId);
  3541.    else if (type == VIDEODB_CONTENT_MOVIES)
  3542. -    exec = FormatSQL("UPDATE movie set c%02d='%s' WHERE idmovie=%i", VIDEODB_ID_FANART, item.GetVideoInfoTag()->m_fanart.m_xml.c_str(), item.GetVideoInfoTag()->m_iDbId);
  3543. +       exec = FormatSQL("UPDATE movie set c%02d='%s' WHERE idMovie=%i", VIDEODB_ID_FANART, item.GetVideoInfoTag()->m_fanart.m_xml.c_str(), item.GetVideoInfoTag()->m_iDbId);
  3544.  
  3545.    try
  3546.    {
  3547. @@ -4026,7 +4033,7 @@
  3548.          }
  3549.          if (!thumb || !fanart) // use the first item's thumb
  3550.          {
  3551. -          CStdString strSQL = FormatSQL("select strPath, strFileName from movieview join setlinkmovie on setlinkmovie.idMovie=movieview.idmovie where setlinkmovie.idSet=%u",m_pDS->fv("sets.idSet").get_asInt());
  3552. +                   CStdString strSQL = FormatSQL("select strPath, strFileName from movieview join setlinkmovie on setlinkmovie.idMovie=movieview.idMovie where setlinkmovie.idSet=%u",m_pDS->fv("sets.idSet").get_asInt());
  3553.            m_pDS2->query(strSQL.c_str());
  3554.            if (!m_pDS2->eof())
  3555.            {
  3556. @@ -4046,7 +4053,7 @@
  3557.        m_pDS->close();
  3558.      }
  3559.  
  3560. -//    CLog::Log(LOGDEBUG, "%s Time: %d ms", CTimeUtils::GetTimeMS() - time);
  3561. +       //    CLog::Log(LOGDEBUG, "%s Time: %d ms", CTimeUtils::GetTimeMS() - time);
  3562.      return true;
  3563.    }
  3564.    catch (...)
  3565. @@ -4066,11 +4073,11 @@
  3566.      CStdString strSQL;
  3567.      if (g_settings.m_vecProfiles[0].getLockMode() != LOCK_MODE_EVERYONE && !g_passwordManager.bMasterUser)
  3568.      {
  3569. -      strSQL=FormatSQL("select musicvideo.c%02d,musicvideo.idMVideo,actors.strActor,path.strPath from musicvideo join artistlinkmusicvideo on artistlinkmusicvideo.idmvideo=musicvideo.idmvideo join actors on actors.idActor=artistlinkmusicvideo.idartist join files on files.idFile = musicvideo.idfile join path on path.idpath = files.idpath",VIDEODB_ID_MUSICVIDEO_ALBUM);
  3570. +           strSQL=FormatSQL("select musicvideo.c%02d,musicvideo.idMVideo,actors.strActor,path.strPath from musicvideo join artistlinkmusicvideo on artistlinkmusicvideo.idMVideo=musicvideo.idMVideo join actors on actors.idActor=artistlinkmusicvideo.idartist join files on files.idFile = musicvideo.idFile join path on path.idPath = files.idPath",VIDEODB_ID_MUSICVIDEO_ALBUM);
  3571.      }
  3572.      else
  3573.      {
  3574. -      strSQL=FormatSQL("select musicvideo.c%02d,musicvideo.idMVideo,actors.strActor from musicvideo join artistlinkmusicvideo on artistlinkmusicvideo.idmvideo=musicvideo.idmvideo join actors on actors.idActor=artistlinkmusicvideo.idartist",VIDEODB_ID_MUSICVIDEO_ALBUM);
  3575. +           strSQL=FormatSQL("select musicvideo.c%02d,musicvideo.idMVideo,actors.strActor from musicvideo join artistlinkmusicvideo on artistlinkmusicvideo.idMVideo=musicvideo.idMVideo join actors on actors.idActor=artistlinkmusicvideo.idartist",VIDEODB_ID_MUSICVIDEO_ALBUM);
  3576.      }
  3577.      if (idArtist > -1)
  3578.        strSQL += FormatSQL(" where artistlinkmusicvideo.idartist=%i",idArtist);
  3579. @@ -4154,7 +4161,7 @@
  3580.        m_pDS->close();
  3581.      }
  3582.  
  3583. -//    CLog::Log(LOGDEBUG, __FUNCTION__" Time: %d ms", CTimeUtils::GetTimeMS() - time);
  3584. +       //    CLog::Log(LOGDEBUG, __FUNCTION__" Time: %d ms", CTimeUtils::GetTimeMS() - time);
  3585.      return true;
  3586.    }
  3587.    catch (...)
  3588. @@ -4238,10 +4245,10 @@
  3589.        else if (idContent == VIDEODB_CONTENT_TVSHOWS)
  3590.          strSQL=FormatSQL("select distinct actors.idActor,actors.strActor,actors.strThumb from actors,%slinktvshow,tvshow where actors.idActor=%slinktvshow.id%s and %slinktvshow.idShow = tvshow.idShow", type.c_str(), type.c_str(), type.c_str(), type.c_str());
  3591.        else if (idContent == VIDEODB_CONTENT_EPISODES)
  3592. -        strSQL=FormatSQL("select actors.idactor,actors.strActor,actors.strThumb,count(1),count(files.playCount) from %slinkepisode,actors,episode,files where actors.idactor=%slinkepisode.id%s and %slinkepisode.idEpisode=episode.idEpisode and files.idfile=episode.idfile group by actors.idactor", type.c_str(), type.c_str(), type.c_str(), type.c_str());
  3593. +               strSQL=FormatSQL("select actors.idActor,actors.strActor,actors.strThumb,count(1),count(files.playCount) from %slinkepisode,actors,episode,files where actors.idActor=%slinkepisode.id%s and %slinkepisode.idEpisode=episode.idEpisode and files.idFile=episode.idFile group by actors.idActor", type.c_str(), type.c_str(), type.c_str(), type.c_str());
  3594.        else if (idContent == VIDEODB_CONTENT_MUSICVIDEOS)
  3595.        {
  3596. -        strSQL=FormatSQL("select actors.idActor,actors.strActor,actors.strThumb,count(1),count(files.playCount) from actors join %slinkmusicvideo on actors.idActor=%slinkmusicvideo.id%s join musicvideo on %slinkmusicvideo.idmvideo = musicvideo.idmvideo join files on files.idFile=musicvideo.idFile", type.c_str(), type.c_str(), type.c_str(), type.c_str());
  3597. +               strSQL=FormatSQL("select actors.idActor,actors.strActor,actors.strThumb,count(1),count(files.playCount) from actors join %slinkmusicvideo on actors.idActor=%slinkmusicvideo.id%s join musicvideo on %slinkmusicvideo.idMVideo = musicvideo.idMVideo join files on files.idFile=musicvideo.idFile", type.c_str(), type.c_str(), type.c_str(), type.c_str());
  3598.          strSQL += " group by actors.idActor";
  3599.        }
  3600.      }
  3601. @@ -4532,22 +4539,22 @@
  3602.      CStdString strIn = FormatSQL("= %i", idShow);
  3603.        GetStackedTvShowList(idShow, strIn);
  3604.  
  3605. -    CStdString strSQL = FormatSQL("select episode.c%02d,path.strPath,tvshow.c%02d,tvshow.c%02d,count(1),count(files.playCount) from episode join tvshow on tvshow.idshow=tvshowlinkepisode.idshow join tvshowlinkepisode on tvshowlinkepisode.idEpisode = episode.idEpisode join files on files.idFile=episode.idFile ", VIDEODB_ID_EPISODE_SEASON, VIDEODB_ID_TV_TITLE, VIDEODB_ID_TV_GENRE);
  3606. +       CStdString strSQL = FormatSQL("select episode.c%02d,path.strPath,tvshow.c%02d,tvshow.c%02d,count(1),count(files.playCount) from episode join tvshow on tvshow.idShow=tvshowlinkepisode.idShow join tvshowlinkepisode on tvshowlinkepisode.idEpisode = episode.idEpisode join files on files.idFile=episode.idFile ", VIDEODB_ID_EPISODE_SEASON, VIDEODB_ID_TV_TITLE, VIDEODB_ID_TV_GENRE);
  3607.      CStdString joins = FormatSQL(" join tvshowlinkpath on tvshowlinkpath.idShow = tvshow.idShow join path on path.idPath = tvshowlinkpath.idPath where tvshow.idShow %s ", strIn.c_str());
  3608.      CStdString extraJoins, extraWhere;
  3609.      if (idActor != -1)
  3610.      {
  3611. -      extraJoins = "join actorlinktvshow on actorlinktvshow.idshow=tvshow.idshow";
  3612. +           extraJoins = "join actorlinktvshow on actorlinktvshow.idShow=tvshow.idShow";
  3613.        extraWhere = FormatSQL("and actorlinktvshow.idActor=%i", idActor);
  3614.      }
  3615.      else if (idDirector != -1)
  3616.      {
  3617. -      extraJoins = "join directorlinktvshow on directorlinktvshow.idshow=tvshow.idshow";
  3618. +           extraJoins = "join directorlinktvshow on directorlinktvshow.idShow=tvshow.idShow";
  3619.        extraWhere = FormatSQL("and directorlinktvshow.idDirector=%i",idDirector);
  3620.      }
  3621.      else if (idGenre != -1)
  3622.      {
  3623. -      extraJoins = "join genrelinktvshow on genrelinktvshow.idshow=tvshow.idshow";
  3624. +           extraJoins = "join genrelinktvshow on genrelinktvshow.idShow=tvshow.idShow";
  3625.        extraWhere = FormatSQL("and genrelinktvshow.idGenre=%i", idGenre);
  3626.      }
  3627.      else if (idYear != -1)
  3628. @@ -4678,17 +4685,17 @@
  3629.  {
  3630.    CStdString where;
  3631.    if (idGenre != -1)
  3632. -    where = FormatSQL("join genrelinkmovie on genrelinkmovie.idmovie=movieview.idmovie where genrelinkmovie.idGenre=%i", idGenre);
  3633. +       where = FormatSQL("join genrelinkmovie on genrelinkmovie.idMovie=movieview.idMovie where genrelinkmovie.idGenre=%i", idGenre);
  3634.    else if (idStudio != -1)
  3635. -    where = FormatSQL("join studiolinkmovie on studiolinkmovie.idmovie=movieview.idmovie where studiolinkmovie.idstudio=%i", idStudio);
  3636. +       where = FormatSQL("join studiolinkmovie on studiolinkmovie.idMovie=movieview.idMovie where studiolinkmovie.idStudio=%i", idStudio);
  3637.    else if (idDirector != -1)
  3638. -    where = FormatSQL("join directorlinkmovie on directorlinkmovie.idmovie=movieview.idmovie where directorlinkmovie.idDirector=%i", idDirector);
  3639. +       where = FormatSQL("join directorlinkmovie on directorlinkmovie.idMovie=movieview.idMovie where directorlinkmovie.idDirector=%i", idDirector);
  3640.    else if (idYear !=-1)
  3641.      where = FormatSQL("where c%02d='%i'",VIDEODB_ID_YEAR,idYear);
  3642.    else if (idActor != -1)
  3643. -    where = FormatSQL("join actorlinkmovie on actorlinkmovie.idmovie=movieview.idmovie join actors on actors.idActor=actorlinkmovie.idActor where actors.idActor=%i",idActor);
  3644. +       where = FormatSQL("join actorlinkmovie on actorlinkmovie.idMovie=movieview.idMovie join actors on actors.idActor=actorlinkmovie.idActor where actors.idActor=%i",idActor);
  3645.    else if (idSet != -1)
  3646. -    where = FormatSQL("join setlinkmovie on setlinkmovie.idMovie=movieview.idmovie where setlinkmovie.idSet=%u",idSet);
  3647. +       where = FormatSQL("join setlinkmovie on setlinkmovie.idMovie=movieview.idMovie where setlinkmovie.idSet=%u",idSet);
  3648.  
  3649.    return GetMoviesByWhere(strBaseDir, where, "", items, idSet == -1);
  3650.  }
  3651. @@ -4713,9 +4720,9 @@
  3652.          setsWhere = " where movie.idMovie in (select movieview.idMovie from movieview " + where + ")";
  3653.        GetSetsNav("videodb://1/7/", items, VIDEODB_CONTENT_MOVIES, setsWhere);
  3654.        if (where.size())
  3655. -        strSQL += where + FormatSQL(" and movieview.idmovie NOT in (select idmovie from setlinkmovie)");
  3656. +               strSQL += where + FormatSQL(" and movieview.idMovie NOT in (select idMovie from setlinkmovie)");
  3657.        else
  3658. -        strSQL += FormatSQL("where movieview.idmovie NOT in (select idmovie from setlinkmovie)");
  3659. +               strSQL += FormatSQL("where movieview.idMovie NOT in (select idMovie from setlinkmovie)");
  3660.      }
  3661.      else
  3662.        strSQL += where;
  3663. @@ -4771,15 +4778,15 @@
  3664.  {
  3665.    CStdString where;
  3666.    if (idGenre != -1)
  3667. -    where = FormatSQL("join genrelinktvshow on genrelinktvshow.idshow=tvshowview.idshow where genrelinktvshow.idGenre=%i ", idGenre);
  3668. +       where = FormatSQL("join genrelinktvshow on genrelinktvshow.idShow=tvshow.idShow where genrelinktvshow.idGenre=%i ", idGenre);
  3669.    else if (idStudio != -1)
  3670. -    where = FormatSQL("join studiolinktvshow on studiolinktvshow.idshow=tvshowview.idshow where studiolinktvshow.idstudio=%i", idStudio);
  3671. +       where = FormatSQL("join studiolinktvshow on studiolinktvshow.idShow=tvshow.idShow where studiolinktvshow.idStudio=%i", idStudio);
  3672.    else if (idDirector != -1)
  3673. -    where = FormatSQL("join directorlinktvshow on directorlinktvshow.idshow=tvshowview.idshow where directorlinktvshow.idDirector=%i", idDirector);
  3674. +       where = FormatSQL("join directorlinktvshow on directorlinktvshow.idShow=tvshow.idShow where directorlinktvshow.idDirector=%i", idDirector);
  3675.    else if (idYear != -1)
  3676.      where = FormatSQL("where c%02d like '%%%i%%'", VIDEODB_ID_TV_PREMIERED,idYear);
  3677.    else if (idActor != -1)
  3678. -    where = FormatSQL("join actorlinktvshow on actorlinktvshow.idshow=tvshowview.idshow join actors on actors.idActor=actorlinktvshow.idActor where actors.idActor=%i",idActor);
  3679. +       where = FormatSQL("join actorlinktvshow on actorlinktvshow.idShow=tvshow.idShow join actors on actors.idActor=actorlinktvshow.idActor where actors.idActor=%i",idActor);
  3680.  
  3681.    return GetTvShowsByWhere(strBaseDir, where, items);
  3682.  }
  3683. @@ -4794,7 +4801,7 @@
  3684.      if (NULL == m_pDB.get()) return false;
  3685.      if (NULL == m_pDS.get()) return false;
  3686.  
  3687. -    CStdString strSQL = "select * from tvshowview " + where;
  3688. +       CStdString strSQL = VIDEO_DATABASE_VIEW_TVSHOW + where;
  3689.      // run query
  3690.      CLog::Log(LOGDEBUG, "%s query: %s", __FUNCTION__, strSQL.c_str());
  3691.      if (!m_pDS->query(strSQL.c_str())) return false;
  3692. @@ -5033,13 +5040,13 @@
  3693.      GetStackedTvShowList(idShow, strIn);
  3694.    CStdString where = FormatSQL("where idShow %s",strIn.c_str());
  3695.    if (idGenre != -1)
  3696. -    where = FormatSQL("join genrelinktvshow on genrelinktvshow.idShow=episodeview.idShow where episodeview.idShow=%i and genrelinktvshow.idgenre=%i",idShow,idGenre);
  3697. +       where = FormatSQL("join genrelinktvshow on genrelinktvshow.idShow=episodeview.idShow where episodeview.idShow=%i and genrelinktvshow.idGenre=%i",idShow,idGenre);
  3698.    else if (idDirector != -1)
  3699. -    where = FormatSQL("join directorlinktvshow on directorlinktvshow.idshow=episodeview.idshow where episodeview.idShow=%i and directorlinktvshow.iddirector=%i",idShow,idDirector);
  3700. +       where = FormatSQL("join directorlinktvshow on directorlinktvshow.idShow=episodeview.idShow where episodeview.idShow=%i and directorlinktvshow.idDirector=%i",idShow,idDirector);
  3701.    else if (idYear !=-1)
  3702.      where=FormatSQL("where idShow=%i and premiered like '%%%i%%'",idShow,idYear);
  3703.    else if (idActor != -1)
  3704. -    where = FormatSQL("join actorlinktvshow on actorlinktvshow.idshow = episodeview.idshow where episodeview.idShow=%i and actorlinktvshow.idactor=%i",idShow,idActor);
  3705. +       where = FormatSQL("join actorlinktvshow on actorlinktvshow.idShow = episodeview.idShow where episodeview.idShow=%i and actorlinktvshow.idActor=%i",idShow,idActor);
  3706.  
  3707.    if (idSeason != -1)
  3708.    {
  3709. @@ -5131,15 +5138,15 @@
  3710.  {
  3711.    CStdString where;
  3712.    if (idGenre != -1)
  3713. -    where = FormatSQL("join genrelinkmusicvideo on genrelinkmusicvideo.idmvideo=musicvideoview.idmvideo where genrelinkmusicvideo.idGenre=%i", idGenre);
  3714. +       where = FormatSQL("join genrelinkmusicvideo on genrelinkmusicvideo.idMVideo=musicvideoview.idMVideo where genrelinkmusicvideo.idGenre=%i", idGenre);
  3715.    else if (idStudio != -1)
  3716. -    where = FormatSQL("join studiolinkmusicvideo on studiolinkmusicvideo.idmvideo=musicvideoview.idmvideo where studiolinkmusicvideo.idstudio=%i", idStudio);
  3717. +       where = FormatSQL("join studiolinkmusicvideo on studiolinkmusicvideo.idMVideo=musicvideoview.idMVideo where studiolinkmusicvideo.idStudio=%i", idStudio);
  3718.    else if (idDirector != -1)
  3719. -    where = FormatSQL("join directorlinkmusicvideo on directorlinkmusicvideo.idmvideo=musicvideoview.idmvideo where directorlinkmusicvideo.idDirector=%i", idDirector);
  3720. +       where = FormatSQL("join directorlinkmusicvideo on directorlinkmusicvideo.idMVideo=musicvideoview.idMVideo where directorlinkmusicvideo.idDirector=%i", idDirector);
  3721.    else if (idYear !=-1)
  3722.      where = FormatSQL("where c%02d='%i'",VIDEODB_ID_MUSICVIDEO_YEAR,idYear);
  3723.    else if (idArtist != -1)
  3724. -    where = FormatSQL("join artistlinkmusicvideo on artistlinkmusicvideo.idmvideo=musicvideoview.idmvideo join actors on actors.idActor=artistlinkmusicvideo.idartist where actors.idActor=%i",idArtist);
  3725. +       where = FormatSQL("join artistlinkmusicvideo on artistlinkmusicvideo.idMVideo=musicvideoview.idMVideo join actors on actors.idActor=artistlinkmusicvideo.idartist where actors.idActor=%i",idArtist);
  3726.    if (idAlbum != -1)
  3727.     {
  3728.      CStdString str2 = FormatSQL(" musicvideoview.c%02d=(select c%02d from musicvideo where idMVideo=%i)",VIDEODB_ID_MUSICVIDEO_ALBUM,VIDEODB_ID_MUSICVIDEO_ALBUM,idAlbum);
  3729. @@ -5148,7 +5155,7 @@
  3730.      else
  3731.        where.Format(" %s %s%s",where.Mid(0).c_str(),"and",str2.c_str());
  3732.    }
  3733. -  
  3734. +
  3735.    return GetMusicVideosByWhere(strBaseDir, where, items);
  3736.  }
  3737.  
  3738. @@ -5160,13 +5167,13 @@
  3739.  
  3740.  bool CVideoDatabase::GetRecentlyAddedEpisodesNav(const CStdString& strBaseDir, CFileItemList& items)
  3741.  {
  3742. -  CStdString where = FormatSQL("order by idepisode desc limit %i", g_advancedSettings.m_iVideoLibraryRecentlyAddedItems);
  3743. +   CStdString where = FormatSQL("order by idEpisode desc limit %i", g_advancedSettings.m_iVideoLibraryRecentlyAddedItems);
  3744.    return GetEpisodesByWhere(strBaseDir, where, items, false);
  3745.  }
  3746.  
  3747.  bool CVideoDatabase::GetRecentlyAddedMusicVideosNav(const CStdString& strBaseDir, CFileItemList& items)
  3748.  {
  3749. -  CStdString where = FormatSQL("order by idmvideo desc limit %i", g_advancedSettings.m_iVideoLibraryRecentlyAddedItems);
  3750. +   CStdString where = FormatSQL("order by idMVideo desc limit %i", g_advancedSettings.m_iVideoLibraryRecentlyAddedItems);
  3751.    return GetMusicVideosByWhere(strBaseDir, where, items);
  3752.  }
  3753.  
  3754. @@ -5249,7 +5256,7 @@
  3755.      if (NULL == m_pDS2.get()) return false;
  3756.  
  3757.      // make sure we use m_pDS2, as this is called in loops using m_pDS
  3758. -    CStdString strSQL=FormatSQL("select idshow from tvshowlinkepisode where idEpisode=%i", idEpisode);
  3759. +       CStdString strSQL=FormatSQL("select idShow from tvshowlinkepisode where idEpisode=%i", idEpisode);
  3760.      m_pDS2->query( strSQL.c_str() );
  3761.  
  3762.      int result=-1;
  3763. @@ -5477,9 +5484,9 @@
  3764.      if (NULL == m_pDS.get()) return;
  3765.  
  3766.      if (g_settings.m_vecProfiles[0].getLockMode() != LOCK_MODE_EVERYONE && !g_passwordManager.bMasterUser)
  3767. -      strSQL=FormatSQL("select genre.idgenre,genre.strgenre,path.strPath from genre,genrelinkmovie,movie,path,files where genre.idGenre=genrelinkMovie.idGenre and genrelinkMovie.idMovie = movie.idMovie and files.idFile=movie.idFile and path.idPath = files.idPath and genre.strGenre like '%%%s%%'",strSearch.c_str());
  3768. +           strSQL=FormatSQL("select genre.idGenre,genre.strgenre,path.strPath from genre,genrelinkmovie,movie,path,files where genre.idGenre=genrelinkMovie.idGenre and genrelinkMovie.idMovie = movie.idMovie and files.idFile=movie.idFile and path.idPath = files.idPath and genre.strGenre like '%%%s%%'",strSearch.c_str());
  3769.      else
  3770. -      strSQL=FormatSQL("select distinct genre.idgenre,genre.strgenre from genre,genrelinkmovie where genrelinkmovie.idgenre=genre.idgenre and strGenre like '%%%s%%'", strSearch.c_str());
  3771. +           strSQL=FormatSQL("select distinct genre.idGenre,genre.strgenre from genre,genrelinkmovie where genrelinkmovie.idGenre=genre.idGenre and strGenre like '%%%s%%'", strSearch.c_str());
  3772.      m_pDS->query( strSQL.c_str() );
  3773.  
  3774.      while (!m_pDS->eof())
  3775. @@ -5518,9 +5525,9 @@
  3776.      if (NULL == m_pDS.get()) return;
  3777.  
  3778.      if (g_settings.m_vecProfiles[0].getLockMode() != LOCK_MODE_EVERYONE && !g_passwordManager.bMasterUser)
  3779. -      strSQL=FormatSQL("select genre.idgenre,genre.strgenre,path.strPath from genre,genrelinktvshow,tvshow,path,tvshowlinkpath where genre.idGenre=genrelinktvshow.idGenre and genrelinktvshow.idshow = tvshow.idshow and path.idPath = tvshowlinkpath.idPath and tvshowlinkpath.idshow = tvshow.idshow and genre.strGenre like '%%%s%%'",strSearch.c_str());
  3780. +           strSQL=FormatSQL("select genre.idGenre,genre.strgenre,path.strPath from genre,genrelinktvshow,tvshow,path,tvshowlinkpath where genre.idGenre=genrelinktvshow.idGenre and genrelinktvshow.idShow = tvshow.idShow and path.idPath = tvshowlinkpath.idPath and tvshowlinkpath.idShow = tvshow.idShow and genre.strGenre like '%%%s%%'",strSearch.c_str());
  3781.      else
  3782. -      strSQL=FormatSQL("select distinct genre.idgenre,genre.strgenre from genre,genrelinktvshow where genrelinktvshow.idgenre=genre.idgenre and strGenre like '%%%s%%'", strSearch.c_str());
  3783. +           strSQL=FormatSQL("select distinct genre.idGenre,genre.strgenre from genre,genrelinktvshow where genrelinktvshow.idGenre=genre.idGenre and strGenre like '%%%s%%'", strSearch.c_str());
  3784.      m_pDS->query( strSQL.c_str() );
  3785.  
  3786.      while (!m_pDS->eof())
  3787. @@ -5558,9 +5565,9 @@
  3788.      if (NULL == m_pDS.get()) return;
  3789.  
  3790.      if (g_settings.m_vecProfiles[0].getLockMode() != LOCK_MODE_EVERYONE && !g_passwordManager.bMasterUser)
  3791. -      strSQL=FormatSQL("select actors.idactor,actors.strActor,path.strPath from actorlinkmovie,actors,movie,files,path where actors.idActor=actorlinkmovie.idActor and actorlinkmovie.idmovie=movie.idmovie and files.idFile = movie.idFile and files.idPath = path.idPath and actors.strActor like '%%%s%%'",strSearch.c_str());
  3792. +           strSQL=FormatSQL("select actors.idActor,actors.strActor,path.strPath from actorlinkmovie,actors,movie,files,path where actors.idActor=actorlinkmovie.idActor and actorlinkmovie.idMovie=movie.idMovie and files.idFile = movie.idFile and files.idPath = path.idPath and actors.strActor like '%%%s%%'",strSearch.c_str());
  3793.      else
  3794. -      strSQL=FormatSQL("select distinct actors.idactor,actors.strActor from actorlinkmovie,actors,movie where actors.idActor=actorlinkmovie.idActor and actorlinkmovie.idmovie=movie.idmovie and actors.strActor like '%%%s%%'",strSearch.c_str());
  3795. +           strSQL=FormatSQL("select distinct actors.idActor,actors.strActor from actorlinkmovie,actors,movie where actors.idActor=actorlinkmovie.idActor and actorlinkmovie.idMovie=movie.idMovie and actors.strActor like '%%%s%%'",strSearch.c_str());
  3796.      m_pDS->query( strSQL.c_str() );
  3797.  
  3798.      while (!m_pDS->eof())
  3799. @@ -5598,9 +5605,9 @@
  3800.      if (NULL == m_pDS.get()) return;
  3801.  
  3802.      if (g_settings.m_vecProfiles[0].getLockMode() != LOCK_MODE_EVERYONE && !g_passwordManager.bMasterUser)
  3803. -      strSQL=FormatSQL("select actors.idactor,actors.strActor,path.strPath from actorlinktvshow,actors,tvshow,path,tvshowlinkpath where actors.idActor=actorlinktvshow.idActor and actorlinktvshow.idshow=tvshow.idshow and tvshowlinkpath.idpath=tvshow.idshow and tvshowlinkpath.idpath=path.idpath and actors.strActor like '%%%s%%'",strSearch.c_str());
  3804. +           strSQL=FormatSQL("select actors.idActor,actors.strActor,path.strPath from actorlinktvshow,actors,tvshow,path,tvshowlinkpath where actors.idActor=actorlinktvshow.idActor and actorlinktvshow.idShow=tvshow.idShow and tvshowlinkpath.idPath=tvshow.idShow and tvshowlinkpath.idPath=path.idPath and actors.strActor like '%%%s%%'",strSearch.c_str());
  3805.      else
  3806. -      strSQL=FormatSQL("select distinct actors.idactor,actors.strActor from actorlinktvshow,actors,tvshow where actors.idActor=actorlinktvshow.idActor and actorlinktvshow.idshow=tvshow.idshow and actors.strActor like '%%%s%%'",strSearch.c_str());
  3807. +           strSQL=FormatSQL("select distinct actors.idActor,actors.strActor from actorlinktvshow,actors,tvshow where actors.idActor=actorlinktvshow.idActor and actorlinktvshow.idShow=tvshow.idShow and actors.strActor like '%%%s%%'",strSearch.c_str());
  3808.      m_pDS->query( strSQL.c_str() );
  3809.  
  3810.      while (!m_pDS->eof())
  3811. @@ -5641,9 +5648,9 @@
  3812.      if (!strSearch.IsEmpty())
  3813.        strLike = "and actors.strActor like '%%%s%%'";
  3814.      if (g_settings.m_vecProfiles[0].getLockMode() != LOCK_MODE_EVERYONE && !g_passwordManager.bMasterUser)
  3815. -      strSQL=FormatSQL("select actors.idactor,actors.strActor,path.strPath from artistlinkmusicvideo,actors,musicvideo,files,path where actors.idActor=artistlinkmusicvideo.idartist and artistlinkmusicvideo.idmvideo=musicvideo.idmvideo and files.idFile = musicvideo.idFile and files.idPath = path.idPath "+strLike,strSearch.c_str());
  3816. +           strSQL=FormatSQL("select actors.idActor,actors.strActor,path.strPath from artistlinkmusicvideo,actors,musicvideo,files,path where actors.idActor=artistlinkmusicvideo.idartist and artistlinkmusicvideo.idMVideo=musicvideo.idMVideo and files.idFile = musicvideo.idFile and files.idPath = path.idPath "+strLike,strSearch.c_str());
  3817.      else
  3818. -      strSQL=FormatSQL("select distinct actors.idactor,actors.strActor from artistlinkmusicvideo,actors where actors.idActor=artistlinkmusicvideo.idartist "+strLike,strSearch.c_str());
  3819. +           strSQL=FormatSQL("select distinct actors.idActor,actors.strActor from artistlinkmusicvideo,actors where actors.idActor=artistlinkmusicvideo.idartist "+strLike,strSearch.c_str());
  3820.      m_pDS->query( strSQL.c_str() );
  3821.  
  3822.      while (!m_pDS->eof())
  3823. @@ -5681,9 +5688,9 @@
  3824.      if (NULL == m_pDS.get()) return;
  3825.  
  3826.      if (g_settings.m_vecProfiles[0].getLockMode() != LOCK_MODE_EVERYONE && !g_passwordManager.bMasterUser)
  3827. -      strSQL=FormatSQL("select genre.idgenre,genre.strgenre,path.strPath from genre,genrelinkmusicvideo,musicvideo,path,files where genre.idGenre=genrelinkmusicvideo.idGenre and genrelinkmusicvideo.idmvideo = musicvideo.idmvideo and files.idFile=musicvideo.idFile and path.idPath = files.idPath and genre.strGenre like '%%%s%%'",strSearch.c_str());
  3828. +           strSQL=FormatSQL("select genre.idGenre,genre.strgenre,path.strPath from genre,genrelinkmusicvideo,musicvideo,path,files where genre.idGenre=genrelinkmusicvideo.idGenre and genrelinkmusicvideo.idMVideo = musicvideo.idMVideo and files.idFile=musicvideo.idFile and path.idPath = files.idPath and genre.strGenre like '%%%s%%'",strSearch.c_str());
  3829.      else
  3830. -      strSQL=FormatSQL("select distinct genre.idgenre,genre.strgenre from genre,genrelinkmusicvideo where genrelinkmusicvideo.idgenre=genre.idgenre and genre.strGenre like '%%%s%%'", strSearch.c_str());
  3831. +           strSQL=FormatSQL("select distinct genre.idGenre,genre.strgenre from genre,genrelinkmusicvideo where genrelinkmusicvideo.idGenre=genre.idGenre and genre.strGenre like '%%%s%%'", strSearch.c_str());
  3832.      m_pDS->query( strSQL.c_str() );
  3833.  
  3834.      while (!m_pDS->eof())
  3835. @@ -5727,12 +5734,12 @@
  3836.        strLike += "like '%%s%%%'";
  3837.      }
  3838.      if (g_settings.m_vecProfiles[0].getLockMode() != LOCK_MODE_EVERYONE && !g_passwordManager.bMasterUser)
  3839. -      strSQL=FormatSQL("select distinct musicvideo.c%02d,musicvideo.idmvideo,path.strPath from musicvideo,files,path where files.idFile = musicvideo.idFile and files.idPath = path.idPath"+strLike,VIDEODB_ID_MUSICVIDEO_ALBUM,strSearch.c_str());
  3840. +           strSQL=FormatSQL("select distinct musicvideo.c%02d,musicvideo.idMVideo,path.strPath from musicvideo,files,path where files.idFile = musicvideo.idFile and files.idPath = path.idPath"+strLike,VIDEODB_ID_MUSICVIDEO_ALBUM,strSearch.c_str());
  3841.      else
  3842.      {
  3843.        if (!strLike.IsEmpty())
  3844.          strLike = "where "+strLike.Mid(4);
  3845. -      strSQL=FormatSQL("select distinct musicvideo.c%02d,musicvideo.idmvideo from musicvideo"+strLike,VIDEODB_ID_MUSICVIDEO_ALBUM,strSearch.c_str());
  3846. +           strSQL=FormatSQL("select distinct musicvideo.c%02d,musicvideo.idMVideo from musicvideo"+strLike,VIDEODB_ID_MUSICVIDEO_ALBUM,strSearch.c_str());
  3847.      }
  3848.      m_pDS->query( strSQL.c_str() );
  3849.  
  3850. @@ -5777,9 +5784,9 @@
  3851.      if (NULL == m_pDS.get()) return;
  3852.  
  3853.      if (g_settings.m_vecProfiles[0].getLockMode() != LOCK_MODE_EVERYONE && !g_passwordManager.bMasterUser)
  3854. -      strSQL = FormatSQL("select musicvideo.idmvideo,musicvideo.c%02d,musicvideo.c%02d,path.strPath from musicvideo,files,path where files.idfile=musicvideo.idfile and files.idPath=path.idPath and musicvideo.c%02d like '%%%s%%'",VIDEODB_ID_MUSICVIDEO_ALBUM,VIDEODB_ID_MUSICVIDEO_TITLE,VIDEODB_ID_MUSICVIDEO_ALBUM,strSearch.c_str());
  3855. +           strSQL = FormatSQL("select musicvideo.idMVideo,musicvideo.c%02d,musicvideo.c%02d,path.strPath from musicvideo,files,path where files.idFile=musicvideo.idFile and files.idPath=path.idPath and musicvideo.c%02d like '%%%s%%'",VIDEODB_ID_MUSICVIDEO_ALBUM,VIDEODB_ID_MUSICVIDEO_TITLE,VIDEODB_ID_MUSICVIDEO_ALBUM,strSearch.c_str());
  3856.      else
  3857. -      strSQL = FormatSQL("select musicvideo.idmvideo,musicvideo.c%02d,musicvideo.c%02d from musicvideo where musicvideo.c%02d like '%%%s%%'",VIDEODB_ID_MUSICVIDEO_ALBUM,VIDEODB_ID_MUSICVIDEO_TITLE,VIDEODB_ID_MUSICVIDEO_ALBUM,strSearch.c_str());
  3858. +           strSQL = FormatSQL("select musicvideo.idMVideo,musicvideo.c%02d,musicvideo.c%02d from musicvideo where musicvideo.c%02d like '%%%s%%'",VIDEODB_ID_MUSICVIDEO_ALBUM,VIDEODB_ID_MUSICVIDEO_TITLE,VIDEODB_ID_MUSICVIDEO_ALBUM,strSearch.c_str());
  3859.      m_pDS->query( strSQL.c_str() );
  3860.  
  3861.      while (!m_pDS->eof())
  3862. @@ -5793,7 +5800,7 @@
  3863.  
  3864.        CFileItemPtr pItem(new CFileItem(m_pDS->fv(1).get_asString()+" - "+m_pDS->fv(2).get_asString()));
  3865.        CStdString strDir;
  3866. -      strDir.Format("3/2/%ld",m_pDS->fv("musicvideo.idmvideo").get_asInt());
  3867. +               strDir.Format("3/2/%ld",m_pDS->fv("musicvideo.idMVideo").get_asInt());
  3868.  
  3869.        pItem->m_strPath="videodb://"+ strDir;
  3870.        pItem->m_bIsFolder=false;
  3871. @@ -5840,7 +5847,7 @@
  3872.      // get songs from returned subtable
  3873.      while (!m_pDS->eof())
  3874.      {
  3875. -      int idMVideo = m_pDS->fv("idmvideo").get_asInt();
  3876. +           int idMVideo = m_pDS->fv("idMVideo").get_asInt();
  3877.        CVideoInfoTag musicvideo = GetDetailsForMusicVideo(m_pDS);
  3878.        if (!checkLocks || g_settings.m_vecProfiles[0].getLockMode() == LOCK_MODE_EVERYONE || g_passwordManager.bMasterUser ||
  3879.            g_passwordManager.IsDatabasePathUnlocked(musicvideo.m_strPath,g_settings.m_videoSources))
  3880. @@ -5873,7 +5880,7 @@
  3881.      if (NULL == m_pDB.get()) return 0;
  3882.      if (NULL == m_pDS.get()) return 0;
  3883.  
  3884. -    CStdString strSQL = "select distinct idmvideo from musicvideoview " + strWhere;
  3885. +       CStdString strSQL = "select distinct idMVideo from musicvideoview " + strWhere;
  3886.      if (!m_pDS->query(strSQL.c_str())) return 0;
  3887.      songIDs.clear();
  3888.      if (m_pDS->num_rows() == 0)
  3889. @@ -5926,7 +5933,7 @@
  3890.      }
  3891.      *item->GetVideoInfoTag() = GetDetailsForMusicVideo(m_pDS);
  3892.      item->m_strPath.Format("videodb://3/2/%ld",item->GetVideoInfoTag()->m_iDbId);
  3893. -    idSong = m_pDS->fv("idmvideo").get_asInt();
  3894. +       idSong = m_pDS->fv("idMVideo").get_asInt();
  3895.      item->SetLabel(item->GetVideoInfoTag()->m_strTitle);
  3896.      m_pDS->close();
  3897.      return true;
  3898. @@ -5949,16 +5956,16 @@
  3899.      if (strAlbum.IsEmpty() && strTitle.IsEmpty())
  3900.      { // we want to return matching artists only
  3901.        if (g_settings.m_vecProfiles[0].getLockMode() != LOCK_MODE_EVERYONE && !g_passwordManager.bMasterUser)
  3902. -        strSQL=FormatSQL("select distinct actors.idactor,path.strPath from artistlinkmusicvideo,actors,musicvideo,files,path where actors.idActor=artistlinkmusicvideo.idartist and artistlinkmusicvideo.idmvideo=musicvideo.idmvideo and files.idFile = musicvideo.idFile and files.idPath = path.idPath and actors.strActor like '%s'",strArtist.c_str());
  3903. +               strSQL=FormatSQL("select distinct actors.idActor,path.strPath from artistlinkmusicvideo,actors,musicvideo,files,path where actors.idActor=artistlinkmusicvideo.idartist and artistlinkmusicvideo.idMVideo=musicvideo.idMVideo and files.idFile = musicvideo.idFile and files.idPath = path.idPath and actors.strActor like '%s'",strArtist.c_str());
  3904.        else
  3905. -        strSQL=FormatSQL("select distinct actors.idactor from artistlinkmusicvideo,actors where actors.idActor=artistlinkmusicvideo.idartist and actors.strActor like '%s'",strArtist.c_str());
  3906. +               strSQL=FormatSQL("select distinct actors.idActor from artistlinkmusicvideo,actors where actors.idActor=artistlinkmusicvideo.idartist and actors.strActor like '%s'",strArtist.c_str());
  3907.      }
  3908.      else
  3909.      { // we want to return the matching musicvideo
  3910.        if (g_settings.m_vecProfiles[0].getLockMode() != LOCK_MODE_EVERYONE && !g_passwordManager.bMasterUser)
  3911. -        strSQL = FormatSQL("select musicvideo.idmvideo from musicvideo,files,path,artistlinkmusicvideo,actors where files.idfile=musicvideo.idfile and files.idPath=path.idPath and musicvideo.%c02d like '%s' and musicvideo.%c02d like '%s' and artistlinkmusicvideo.idmvideo=musicvideo.idmvideo and artistlinkmusicvideo.idartist = actors.idactors and actors.strActor like '%s'",VIDEODB_ID_MUSICVIDEO_ALBUM,strAlbum.c_str(),VIDEODB_ID_MUSICVIDEO_TITLE,strTitle.c_str(),strArtist.c_str());
  3912. +               strSQL = FormatSQL("select musicvideo.idMVideo from musicvideo,files,path,artistlinkmusicvideo,actors where files.idFile=musicvideo.idFile and files.idPath=path.idPath and musicvideo.%c02d like '%s' and musicvideo.%c02d like '%s' and artistlinkmusicvideo.idMVideo=musicvideo.idMVideo and artistlinkmusicvideo.idartist = actors.idActors and actors.strActor like '%s'",VIDEODB_ID_MUSICVIDEO_ALBUM,strAlbum.c_str(),VIDEODB_ID_MUSICVIDEO_TITLE,strTitle.c_str(),strArtist.c_str());
  3913.        else
  3914. -        strSQL = FormatSQL("select musicvideo.idmvideo from musicvideo join artistlinkmusicvideo on artistlinkmusicvideo.idmvideo=musicvideo.idmvideo join actors on actors.idactor=artistlinkmusicvideo.idartist where musicvideo.c%02d like '%s' and musicvideo.c%02d like '%s' and actors.strActor like '%s'",VIDEODB_ID_MUSICVIDEO_ALBUM,strAlbum.c_str(),VIDEODB_ID_MUSICVIDEO_TITLE,strTitle.c_str(),strArtist.c_str());
  3915. +               strSQL = FormatSQL("select musicvideo.idMVideo from musicvideo join artistlinkmusicvideo on artistlinkmusicvideo.idMVideo=musicvideo.idMVideo join actors on actors.idActor=artistlinkmusicvideo.idartist where musicvideo.c%02d like '%s' and musicvideo.c%02d like '%s' and actors.strActor like '%s'",VIDEODB_ID_MUSICVIDEO_ALBUM,strAlbum.c_str(),VIDEODB_ID_MUSICVIDEO_TITLE,strTitle.c_str(),strArtist.c_str());
  3916.      }
  3917.      m_pDS->query( strSQL.c_str() );
  3918.  
  3919. @@ -5993,9 +6000,9 @@
  3920.      if (NULL == m_pDS.get()) return;
  3921.  
  3922.      if (g_settings.m_vecProfiles[0].getLockMode() != LOCK_MODE_EVERYONE && !g_passwordManager.bMasterUser)
  3923. -      strSQL = FormatSQL("select movie.idmovie,movie.c%02d,path.strPath from movie,files,path where files.idfile=movie.idfile and files.idPath=path.idPath and movie.c%02d like '%%%s%%'",VIDEODB_ID_TITLE,VIDEODB_ID_TITLE,strSearch.c_str());
  3924. +           strSQL = FormatSQL("select movie.idMovie,movie.c%02d,path.strPath from movie,files,path where files.idFile=movie.idFile and files.idPath=path.idPath and movie.c%02d like '%%%s%%'",VIDEODB_ID_TITLE,VIDEODB_ID_TITLE,strSearch.c_str());
  3925.      else
  3926. -      strSQL = FormatSQL("select movie.idmovie,movie.c%02d from movie where movie.c%02d like '%%%s%%'",VIDEODB_ID_TITLE,VIDEODB_ID_TITLE,strSearch.c_str());
  3927. +           strSQL = FormatSQL("select movie.idMovie,movie.c%02d from movie where movie.c%02d like '%%%s%%'",VIDEODB_ID_TITLE,VIDEODB_ID_TITLE,strSearch.c_str());
  3928.      m_pDS->query( strSQL.c_str() );
  3929.  
  3930.      while (!m_pDS->eof())
  3931. @@ -6039,9 +6046,9 @@
  3932.      if (NULL == m_pDS.get()) return;
  3933.  
  3934.      if (g_settings.m_vecProfiles[0].getLockMode() != LOCK_MODE_EVERYONE && !g_passwordManager.bMasterUser)
  3935. -      strSQL = FormatSQL("select tvshow.idshow,tvshow.c%02d,path.strPath from tvshow,path,tvshowlinkpath where tvshowlinkpath.idpath=path.idpath and tvshowlinkpath.idshow = tvshow.idshow and tvshow.c%02d like '%%%s%%'",VIDEODB_ID_TV_TITLE,VIDEODB_ID_TV_TITLE,strSearch.c_str());
  3936. +           strSQL = FormatSQL("select tvshow.idShow,tvshow.c%02d,path.strPath from tvshow,path,tvshowlinkpath where tvshowlinkpath.idPath=path.idPath and tvshowlinkpath.idShow = tvshow.idShow and tvshow.c%02d like '%%%s%%'",VIDEODB_ID_TV_TITLE,VIDEODB_ID_TV_TITLE,strSearch.c_str());
  3937.      else
  3938. -      strSQL = FormatSQL("select tvshow.idshow,tvshow.c%02d from tvshow where tvshow.c%02d like '%%%s%%'",VIDEODB_ID_TV_TITLE,VIDEODB_ID_TV_TITLE,strSearch.c_str());
  3939. +           strSQL = FormatSQL("select tvshow.idShow,tvshow.c%02d from tvshow where tvshow.c%02d like '%%%s%%'",VIDEODB_ID_TV_TITLE,VIDEODB_ID_TV_TITLE,strSearch.c_str());
  3940.      m_pDS->query( strSQL.c_str() );
  3941.  
  3942.      while (!m_pDS->eof())
  3943. @@ -6055,11 +6062,11 @@
  3944.  
  3945.        CFileItemPtr pItem(new CFileItem(m_pDS->fv(1).get_asString()));
  3946.        CStdString strDir;
  3947. -      strDir.Format("2/2/%ld/", m_pDS->fv("tvshow.idshow").get_asInt());
  3948. +               strDir.Format("2/2/%ld/", m_pDS->fv("tvshow.idShow").get_asInt());
  3949.  
  3950.        pItem->m_strPath="videodb://"+ strDir;
  3951.        pItem->m_bIsFolder=true;
  3952. -      pItem->GetVideoInfoTag()->m_iDbId = m_pDS->fv("tvshow.idshow").get_asInt();
  3953. +               pItem->GetVideoInfoTag()->m_iDbId = m_pDS->fv("tvshow.idShow").get_asInt();
  3954.        items.Add(pItem);
  3955.        m_pDS->next();
  3956.      }
  3957. @@ -6081,9 +6088,9 @@
  3958.      if (NULL == m_pDS.get()) return;
  3959.  
  3960.      if (g_settings.m_vecProfiles[0].getLockMode() != LOCK_MODE_EVERYONE && !g_passwordManager.bMasterUser)
  3961. -      strSQL = FormatSQL("select episode.idepisode,episode.c%02d,episode.c%02d,tvshowlinkepisode.idshow,tvshow.c%02d,path.strPath from episode,files,path,tvshowlinkepisode,tvshow where files.idfile=episode.idfile and tvshowlinkepisode.idepisode=episode.idepisode and tvshowlinkepisode.idshow=tvshow.idshow and files.idPath=path.idPath and episode.c%02d like '%%%s%%'",VIDEODB_ID_EPISODE_TITLE,VIDEODB_ID_EPISODE_SEASON,VIDEODB_ID_TV_TITLE,VIDEODB_ID_EPISODE_TITLE,strSearch.c_str());
  3962. +           strSQL = FormatSQL("select episode.idEpisode,episode.c%02d,episode.c%02d,tvshowlinkepisode.idShow,tvshow.c%02d,path.strPath from episode,files,path,tvshowlinkepisode,tvshow where files.idFile=episode.idFile and tvshowlinkepisode.idEpisode=episode.idEpisode and tvshowlinkepisode.idShow=tvshow.idShow and files.idPath=path.idPath and episode.c%02d like '%%%s%%'",VIDEODB_ID_EPISODE_TITLE,VIDEODB_ID_EPISODE_SEASON,VIDEODB_ID_TV_TITLE,VIDEODB_ID_EPISODE_TITLE,strSearch.c_str());
  3963.      else
  3964. -      strSQL = FormatSQL("select episode.idepisode,episode.c%02d,episode.c%02d,tvshowlinkepisode.idshow,tvshow.c%02d from episode,tvshowlinkepisode,tvshow where tvshowlinkepisode.idepisode=episode.idepisode and tvshow.idshow=tvshowlinkepisode.idshow and episode.c%02d like '%%%s%%'",VIDEODB_ID_EPISODE_TITLE,VIDEODB_ID_EPISODE_SEASON,VIDEODB_ID_TV_TITLE,VIDEODB_ID_EPISODE_TITLE,strSearch.c_str());
  3965. +           strSQL = FormatSQL("select episode.idEpisode,episode.c%02d,episode.c%02d,tvshowlinkepisode.idShow,tvshow.c%02d from episode,tvshowlinkepisode,tvshow where tvshowlinkepisode.idEpisode=episode.idEpisode and tvshow.idShow=tvshowlinkepisode.idShow and episode.c%02d like '%%%s%%'",VIDEODB_ID_EPISODE_TITLE,VIDEODB_ID_EPISODE_SEASON,VIDEODB_ID_TV_TITLE,VIDEODB_ID_EPISODE_TITLE,strSearch.c_str());
  3966.      m_pDS->query( strSQL.c_str() );
  3967.  
  3968.      while (!m_pDS->eof())
  3969. @@ -6096,7 +6103,7 @@
  3970.          }
  3971.  
  3972.        CFileItemPtr pItem(new CFileItem(m_pDS->fv(1).get_asString()+" ("+m_pDS->fv(4).get_asString()+")"));
  3973. -      pItem->m_strPath.Format("videodb://2/2/%ld/%ld/%ld",m_pDS->fv("tvshowlinkepisode.idshow").get_asInt(),m_pDS->fv(2).get_asInt(),m_pDS->fv(0).get_asInt());
  3974. +               pItem->m_strPath.Format("videodb://2/2/%ld/%ld/%ld",m_pDS->fv("tvshowlinkepisode.idShow").get_asInt(),m_pDS->fv(2).get_asInt(),m_pDS->fv(0).get_asInt());
  3975.        pItem->m_bIsFolder=false;
  3976.        items.Add(pItem);
  3977.        m_pDS->next();
  3978. @@ -6111,10 +6118,10 @@
  3979.  
  3980.  void CVideoDatabase::GetMusicVideosByName(const CStdString& strSearch, CFileItemList& items)
  3981.  {
  3982. -// Alternative searching - not quite as fast though due to
  3983. -// retrieving all information
  3984. -//  CStdString where = FormatSQL("where c%02d like '%s%%' or c%02d like '%% %s%%'", VIDEODB_ID_MUSICVIDEO_TITLE, strSearch.c_str(), VIDEODB_ID_MUSICVIDEO_TITLE, strSearch.c_str());
  3985. -//  GetMusicVideosByWhere("videodb://3/2/", where, items);
  3986. +   // Alternative searching - not quite as fast though due to
  3987. +   // retrieving all information
  3988. +   //  CStdString where = FormatSQL("where c%02d like '%s%%' or c%02d like '%% %s%%'", VIDEODB_ID_MUSICVIDEO_TITLE, strSearch.c_str(), VIDEODB_ID_MUSICVIDEO_TITLE, strSearch.c_str());
  3989. +   //  GetMusicVideosByWhere("videodb://3/2/", where, items);
  3990.    CStdString strSQL;
  3991.  
  3992.    try
  3993. @@ -6123,9 +6130,9 @@
  3994.      if (NULL == m_pDS.get()) return;
  3995.  
  3996.      if (g_settings.m_vecProfiles[0].getLockMode() != LOCK_MODE_EVERYONE && !g_passwordManager.bMasterUser)
  3997. -      strSQL = FormatSQL("select musicvideo.idmvideo,musicvideo.c%02d,path.strPath from musicvideo,files,path where files.idfile=musicvideo.idfile and files.idPath=path.idPath and musicvideo.c%02d like '%%%s%%'",VIDEODB_ID_MUSICVIDEO_TITLE,VIDEODB_ID_MUSICVIDEO_TITLE,strSearch.c_str());
  3998. +           strSQL = FormatSQL("select musicvideo.idMVideo,musicvideo.c%02d,path.strPath from musicvideo,files,path where files.idFile=musicvideo.idFile and files.idPath=path.idPath and musicvideo.c%02d like '%%%s%%'",VIDEODB_ID_MUSICVIDEO_TITLE,VIDEODB_ID_MUSICVIDEO_TITLE,strSearch.c_str());
  3999.      else
  4000. -      strSQL = FormatSQL("select musicvideo.idmvideo,musicvideo.c%02d from musicvideo where musicvideo.c%02d like '%%%s%%'",VIDEODB_ID_MUSICVIDEO_TITLE,VIDEODB_ID_MUSICVIDEO_TITLE,strSearch.c_str());
  4001. +           strSQL = FormatSQL("select musicvideo.idMVideo,musicvideo.c%02d from musicvideo where musicvideo.c%02d like '%%%s%%'",VIDEODB_ID_MUSICVIDEO_TITLE,VIDEODB_ID_MUSICVIDEO_TITLE,strSearch.c_str());
  4002.      m_pDS->query( strSQL.c_str() );
  4003.  
  4004.      while (!m_pDS->eof())
  4005. @@ -6139,7 +6146,7 @@
  4006.  
  4007.        CFileItemPtr pItem(new CFileItem(m_pDS->fv(1).get_asString()));
  4008.        CStdString strDir;
  4009. -      strDir.Format("3/2/%ld",m_pDS->fv("musicvideo.idmvideo").get_asInt());
  4010. +               strDir.Format("3/2/%ld",m_pDS->fv("musicvideo.idMVideo").get_asInt());
  4011.  
  4012.        pItem->m_strPath="videodb://"+ strDir;
  4013.        pItem->m_bIsFolder=false;
  4014. @@ -6156,12 +6163,12 @@
  4015.  
  4016.  void CVideoDatabase::GetEpisodesByPlot(const CStdString& strSearch, CFileItemList& items)
  4017.  {
  4018. -// Alternative searching - not quite as fast though due to
  4019. -// retrieving all information
  4020. -//  CStdString where = FormatSQL("where c%02d like '%s%%' or c%02d like '%% %s%%'", VIDEODB_ID_EPISODE_PLOT, strSearch.c_str(), VIDEODB_ID_EPISODE_PLOT, strSearch.c_str());
  4021. -//  where += FormatSQL("or c%02d like '%s%%' or c%02d like '%% %s%%'", VIDEODB_ID_EPISODE_TITLE, strSearch.c_str(), VIDEODB_ID_EPISODE_TITLE, strSearch.c_str());
  4022. -//  GetEpisodesByWhere("videodb://2/2/", where, items);
  4023. -//  return;
  4024. +   // Alternative searching - not quite as fast though due to
  4025. +   // retrieving all information
  4026. +   //  CStdString where = FormatSQL("where c%02d like '%s%%' or c%02d like '%% %s%%'", VIDEODB_ID_EPISODE_PLOT, strSearch.c_str(), VIDEODB_ID_EPISODE_PLOT, strSearch.c_str());
  4027. +   //  where += FormatSQL("or c%02d like '%s%%' or c%02d like '%% %s%%'", VIDEODB_ID_EPISODE_TITLE, strSearch.c_str(), VIDEODB_ID_EPISODE_TITLE, strSearch.c_str());
  4028. +   //  GetEpisodesByWhere("videodb://2/2/", where, items);
  4029. +   //  return;
  4030.    CStdString strSQL;
  4031.  
  4032.    try
  4033. @@ -6170,9 +6177,9 @@
  4034.      if (NULL == m_pDS.get()) return;
  4035.  
  4036.      if (g_settings.m_vecProfiles[0].getLockMode() != LOCK_MODE_EVERYONE && !g_passwordManager.bMasterUser)
  4037. -      strSQL = FormatSQL("select episode.idepisode,episode.c%02d,episode.c%02d,tvshowlinkepisode.idshow,tvshow.c%02d,path.strPath from episode,files,path,tvshowlinkepisode,tvshow where files.idfile=episode.idfile and tvshowlinkepisode.idepisode=episode.idepisode and files.idPath=path.idPath and tvshow.idshow=tvshowlinkepisode.idshow and episode.c%02d like '%%%s%%'",VIDEODB_ID_EPISODE_TITLE,VIDEODB_ID_EPISODE_SEASON,VIDEODB_ID_TV_TITLE,VIDEODB_ID_EPISODE_PLOT,strSearch.c_str());
  4038. +           strSQL = FormatSQL("select episode.idEpisode,episode.c%02d,episode.c%02d,tvshowlinkepisode.idShow,tvshow.c%02d,path.strPath from episode,files,path,tvshowlinkepisode,tvshow where files.idFile=episode.idFile and tvshowlinkepisode.idEpisode=episode.idEpisode and files.idPath=path.idPath and tvshow.idShow=tvshowlinkepisode.idShow and episode.c%02d like '%%%s%%'",VIDEODB_ID_EPISODE_TITLE,VIDEODB_ID_EPISODE_SEASON,VIDEODB_ID_TV_TITLE,VIDEODB_ID_EPISODE_PLOT,strSearch.c_str());
  4039.      else
  4040. -      strSQL = FormatSQL("select episode.idepisode,episode.c%02d,episode.c%02d,tvshowlinkepisode.idshow,tvshow.c%02d from episode,tvshowlinkepisode,tvshow where tvshowlinkepisode.idepisode=episode.idepisode and tvshow.idshow=tvshowlinkepisode.idshow and episode.c%02d like '%%%s%%'",VIDEODB_ID_EPISODE_TITLE,VIDEODB_ID_EPISODE_SEASON,VIDEODB_ID_TV_TITLE,VIDEODB_ID_EPISODE_PLOT,strSearch.c_str());
  4041. +           strSQL = FormatSQL("select episode.idEpisode,episode.c%02d,episode.c%02d,tvshowlinkepisode.idShow,tvshow.c%02d from episode,tvshowlinkepisode,tvshow where tvshowlinkepisode.idEpisode=episode.idEpisode and tvshow.idShow=tvshowlinkepisode.idShow and episode.c%02d like '%%%s%%'",VIDEODB_ID_EPISODE_TITLE,VIDEODB_ID_EPISODE_SEASON,VIDEODB_ID_TV_TITLE,VIDEODB_ID_EPISODE_PLOT,strSearch.c_str());
  4042.      m_pDS->query( strSQL.c_str() );
  4043.  
  4044.      while (!m_pDS->eof())
  4045. @@ -6185,7 +6192,7 @@
  4046.          }
  4047.  
  4048.        CFileItemPtr pItem(new CFileItem(m_pDS->fv(1).get_asString()+" ("+m_pDS->fv(4).get_asString()+")"));
  4049. -      pItem->m_strPath.Format("videodb://2/2/%ld/%ld/%ld",m_pDS->fv("tvshowlinkepisode.idshow").get_asInt(),m_pDS->fv(2).get_asInt(),m_pDS->fv(0).get_asInt());
  4050. +               pItem->m_strPath.Format("videodb://2/2/%ld/%ld/%ld",m_pDS->fv("tvshowlinkepisode.idShow").get_asInt(),m_pDS->fv(2).get_asInt(),m_pDS->fv(0).get_asInt());
  4051.        pItem->m_bIsFolder=false;
  4052.        items.Add(pItem);
  4053.        m_pDS->next();
  4054. @@ -6208,9 +6215,9 @@
  4055.      if (NULL == m_pDS.get()) return;
  4056.  
  4057.      if (g_settings.m_vecProfiles[0].getLockMode() != LOCK_MODE_EVERYONE && !g_passwordManager.bMasterUser)
  4058. -      strSQL = FormatSQL("select movie.idmovie, movie.c%02d, path.strPath from movie,files,path where files.idfile=movie.idfile and files.idPath=path.idPath and (movie.c%02d like '%%%s%%' or movie.c%02d like '%%%s%%' or movie.c%02d like '%%%s%%')",VIDEODB_ID_TITLE,VIDEODB_ID_PLOT,strSearch.c_str(),VIDEODB_ID_PLOTOUTLINE,strSearch.c_str(),VIDEODB_ID_TAGLINE,strSearch.c_str());
  4059. +           strSQL = FormatSQL("select movie.idMovie, movie.c%02d, path.strPath from movie,files,path where files.idFile=movie.idFile and files.idPath=path.idPath and (movie.c%02d like '%%%s%%' or movie.c%02d like '%%%s%%' or movie.c%02d like '%%%s%%')",VIDEODB_ID_TITLE,VIDEODB_ID_PLOT,strSearch.c_str(),VIDEODB_ID_PLOTOUTLINE,strSearch.c_str(),VIDEODB_ID_TAGLINE,strSearch.c_str());
  4060.      else
  4061. -      strSQL = FormatSQL("select movie.idmovie, movie.c%02d from movie where (movie.c%02d like '%%%s%%' or movie.c%02d like '%%%s%%' or movie.c%02d like '%%%s%%')",VIDEODB_ID_TITLE,VIDEODB_ID_PLOT,strSearch.c_str(),VIDEODB_ID_PLOTOUTLINE,strSearch.c_str(),VIDEODB_ID_TAGLINE,strSearch.c_str());
  4062. +           strSQL = FormatSQL("select movie.idMovie, movie.c%02d from movie where (movie.c%02d like '%%%s%%' or movie.c%02d like '%%%s%%' or movie.c%02d like '%%%s%%')",VIDEODB_ID_TITLE,VIDEODB_ID_PLOT,strSearch.c_str(),VIDEODB_ID_PLOTOUTLINE,strSearch.c_str(),VIDEODB_ID_TAGLINE,strSearch.c_str());
  4063.  
  4064.      m_pDS->query( strSQL.c_str() );
  4065.  
  4066. @@ -6249,9 +6256,9 @@
  4067.      if (NULL == m_pDS.get()) return;
  4068.  
  4069.      if (g_settings.m_vecProfiles[0].getLockMode() != LOCK_MODE_EVERYONE && !g_passwordManager.bMasterUser)
  4070. -      strSQL = FormatSQL("select distinct directorlinkmovie.idDirector,actors.strActor,path.strPath from movie,files,path,actors,directorlinkmovie where files.idfile=movie.idfile and files.idPath=path.idPath and directorlinkmovie.idmovie = movie.idMovie and directorlinkmovie.idDirector = actors.idActor and actors.strActor like '%%%s%%'",strSearch.c_str());
  4071. +           strSQL = FormatSQL("select distinct directorlinkmovie.idDirector,actors.strActor,path.strPath from movie,files,path,actors,directorlinkmovie where files.idFile=movie.idFile and files.idPath=path.idPath and directorlinkmovie.idMovie = movie.idMovie and directorlinkmovie.idDirector = actors.idActor and actors.strActor like '%%%s%%'",strSearch.c_str());
  4072.      else
  4073. -      strSQL = FormatSQL("select distinct directorlinkmovie.idDirector,actors.strActor from movie,actors,directorlinkmovie where directorlinkmovie.idmovie = movie.idMovie and directorlinkmovie.idDirector = actors.idActor and actors.strActor like '%%%s%%'",strSearch.c_str());
  4074. +           strSQL = FormatSQL("select distinct directorlinkmovie.idDirector,actors.strActor from movie,actors,directorlinkmovie where directorlinkmovie.idMovie = movie.idMovie and directorlinkmovie.idDirector = actors.idActor and actors.strActor like '%%%s%%'",strSearch.c_str());
  4075.  
  4076.      m_pDS->query( strSQL.c_str() );
  4077.  
  4078. @@ -6291,9 +6298,9 @@
  4079.      if (NULL == m_pDS.get()) return;
  4080.  
  4081.      if (g_settings.m_vecProfiles[0].getLockMode() != LOCK_MODE_EVERYONE && !g_passwordManager.bMasterUser)
  4082. -      strSQL = FormatSQL("select distinct directorlinktvshow.idDirector,actors.strActor,path.strPath from tvshow,path,actors,directorlinktvshow,tvshowlinkpath where tvshowlinkpath.idPath=path.idPath and tvshowlinkpath.idshow=tvshow.idshow and directorlinktvshow.idshow = tvshow.idshow and directorlinktvshow.idDirector = actors.idActor and actors.strActor like '%%%s%%'",strSearch.c_str());
  4083. +           strSQL = FormatSQL("select distinct directorlinktvshow.idDirector,actors.strActor,path.strPath from tvshow,path,actors,directorlinktvshow,tvshowlinkpath where tvshowlinkpath.idPath=path.idPath and tvshowlinkpath.idShow=tvshow.idShow and directorlinktvshow.idShow = tvshow.idShow and directorlinktvshow.idDirector = actors.idActor and actors.strActor like '%%%s%%'",strSearch.c_str());
  4084.      else
  4085. -      strSQL = FormatSQL("select distinct directorlinktvshow.idDirector,actors.strActor from tvshow,actors,directorlinktvshow where directorlinktvshow.idshow = tvshow.idshow and directorlinktvshow.idDirector = actors.idActor and actors.strActor like '%%%s%%'",strSearch.c_str());
  4086. +           strSQL = FormatSQL("select distinct directorlinktvshow.idDirector,actors.strActor from tvshow,actors,directorlinktvshow where directorlinktvshow.idShow = tvshow.idShow and directorlinktvshow.idDirector = actors.idActor and actors.strActor like '%%%s%%'",strSearch.c_str());
  4087.  
  4088.      m_pDS->query( strSQL.c_str() );
  4089.  
  4090. @@ -6333,9 +6340,9 @@
  4091.      if (NULL == m_pDS.get()) return;
  4092.  
  4093.      if (g_settings.m_vecProfiles[0].getLockMode() != LOCK_MODE_EVERYONE && !g_passwordManager.bMasterUser)
  4094. -      strSQL = FormatSQL("select distinct directorlinkmusicvideo.idDirector,actors.strActor,path.strPath from musicvideo,files,path,actors,directorlinkmusicvideo where files.idfile=musicvideo.idfile and files.idPath=path.idPath and directorlinkmusicvideo.idmvideo = musicvideo.idmvideo and directorlinkmusicvideo.idDirector = actors.idActor and actors.strActor like '%%%s%%'",strSearch.c_str());
  4095. +           strSQL = FormatSQL("select distinct directorlinkmusicvideo.idDirector,actors.strActor,path.strPath from musicvideo,files,path,actors,directorlinkmusicvideo where files.idFile=musicvideo.idFile and files.idPath=path.idPath and directorlinkmusicvideo.idMVideo = musicvideo.idMVideo and directorlinkmusicvideo.idDirector = actors.idActor and actors.strActor like '%%%s%%'",strSearch.c_str());
  4096.      else
  4097. -      strSQL = FormatSQL("select distinct directorlinkmusicvideo.idDirector,actors.strActor from musicvideo,actors,directorlinkmusicvideo where directorlinkmusicvideo.idmvideo = musicvideo.idmvideo and directorlinkmusicvideo.idDirector = actors.idActor and actors.strActor like '%%%s%%'",strSearch.c_str());
  4098. +           strSQL = FormatSQL("select distinct directorlinkmusicvideo.idDirector,actors.strActor from musicvideo,actors,directorlinkmusicvideo where directorlinkmusicvideo.idMVideo = musicvideo.idMVideo and directorlinkmusicvideo.idDirector = actors.idActor and actors.strActor like '%%%s%%'",strSearch.c_str());
  4099.  
  4100.      m_pDS->query( strSQL.c_str() );
  4101.  
  4102. @@ -6388,7 +6395,7 @@
  4103.        CStdString strPaths;
  4104.        for (unsigned int i=0;i<paths->size();++i )
  4105.          strPaths.Format("%s,%i",strPaths.Mid(0).c_str(),paths->at(i));
  4106. -      sql = FormatSQL("select * from files,path where files.idpath=path.idPath and path.idPath in (%s)",strPaths.Mid(1).c_str());
  4107. +           sql = FormatSQL("select * from files,path where files.idPath=path.idPath and path.idPath in (%s)",strPaths.Mid(1).c_str());
  4108.      }
  4109.      else
  4110.        sql = "select * from files, path where files.idPath = path.idPath";
  4111. @@ -6600,18 +6607,18 @@
  4112.      {
  4113.        strIds.TrimLeft(" ");
  4114.        strIds.TrimRight(",");
  4115. -      sql = FormatSQL("delete from path where idpath in (%s)",strIds.c_str());
  4116. +           sql = FormatSQL("delete from path where idPath in (%s)",strIds.c_str());
  4117.        m_pDS->exec(sql.c_str());
  4118. -      sql = FormatSQL("delete from tvshowlinkpath where idpath in (%s)",strIds.c_str());
  4119. +           sql = FormatSQL("delete from tvshowlinkpath where idPath in (%s)",strIds.c_str());
  4120.        m_pDS->exec(sql.c_str());
  4121.      }
  4122.  
  4123.      CLog::Log(LOGDEBUG, "%s Cleaning tvshow table", __FUNCTION__);
  4124. -    sql = "delete from tvshow where idshow not in (select idshow from tvshowlinkpath)";
  4125. +       sql = "delete from tvshow where idShow not in (select idShow from tvshowlinkpath)";
  4126.      m_pDS->exec(sql.c_str());
  4127.      sql = "delete from tvshow where idShow in (select tvshow.idShow from tvshow "
  4128. -                                               "join tvshowlinkpath on tvshow.idshow=tvshowlinkpath.idshow "
  4129. -                                               "join path on path.idpath=tvshowlinkpath.idpath "
  4130. +           "join tvshowlinkpath on tvshow.idShow=tvshowlinkpath.idShow "
  4131. +           "join path on path.idPath=tvshowlinkpath.idPath "
  4132.                                                 "where tvshow.idShow not in (select idShow from tvshowlinkepisode) "
  4133.                                                 "and path.strContent == '')";
  4134.      m_pDS->exec(sql.c_str());
  4135. @@ -6625,7 +6632,7 @@
  4136.      m_pDS->exec(sql.c_str());
  4137.  
  4138.      CLog::Log(LOGDEBUG, "%s Cleaning tvshowlinkpath table", __FUNCTION__);
  4139. -    sql = "delete from tvshowlinkpath where idshow not in (select idShow from tvshow)";
  4140. +       sql = "delete from tvshowlinkpath where idShow not in (select idShow from tvshow)";
  4141.      m_pDS->exec(sql.c_str());
  4142.  
  4143.      CLog::Log(LOGDEBUG, "%s Cleaning genrelinktvshow table", __FUNCTION__);
  4144. @@ -6639,7 +6646,7 @@
  4145.      m_pDS->exec(sql.c_str());
  4146.  
  4147.      CLog::Log(LOGDEBUG, "%s Cleaning musicvideo table", __FUNCTION__);
  4148. -    sql = "delete from musicvideo where idmvideo in " + musicVideosToDelete;
  4149. +       sql = "delete from musicvideo where idMVideo in " + musicVideosToDelete;
  4150.      m_pDS->exec(sql.c_str());
  4151.  
  4152.      CLog::Log(LOGDEBUG, "%s Cleaning artistlinkmusicvideo table", __FUNCTION__);
  4153. @@ -6709,7 +6716,7 @@
  4154.      if (CDirectory::Create(TVFolder))
  4155.      { // right - grab the episodes and dump them as well
  4156.        CFileItemList episodes;
  4157. -      CStdString where = FormatSQL("where idshow=%i", items[i]->GetVideoInfoTag()->m_iDbId);
  4158. +           CStdString where = FormatSQL("where idShow=%i", items[i]->GetVideoInfoTag()->m_iDbId);
  4159.        GetEpisodesByWhere("videodb://2/2/", where, episodes);
  4160.        for (int i = 0; i < episodes.Size(); i++)
  4161.        {
  4162. @@ -6868,14 +6875,14 @@
  4163.          if (!cachedThumb.IsEmpty() && (overwrite || !CFile::Exists(savedThumb, false)))
  4164.            if (!CFile::Cache(cachedThumb, savedThumb))
  4165.              CLog::Log(LOGERROR, "%s: Movie thumb export failed! ('%s' -> '%s')", __FUNCTION__, cachedThumb.c_str(), savedThumb.c_str());
  4166. -        
  4167. +
  4168.          CStdString cachedFanart(item.GetCachedFanart());
  4169.          CStdString savedFanart(CUtil::ReplaceExtension(savedThumb, "-fanart.jpg"));
  4170. -        
  4171. +
  4172.          if (CFile::Exists(cachedFanart, false) && (overwrite || !CFile::Exists(savedFanart, false)))
  4173.            if (!CFile::Cache(cachedFanart, savedFanart))
  4174.              CLog::Log(LOGERROR, "%s: Movie fanart export failed! ('%s' -> '%s')", __FUNCTION__, cachedFanart.c_str(), savedFanart.c_str());
  4175. -        
  4176. +
  4177.          if (actorThumbs)
  4178.            ExportActorThumbs(actorsDir, movie, singleFiles, overwrite);
  4179.        }
  4180. @@ -6965,7 +6972,7 @@
  4181.      m_pDS->close();
  4182.  
  4183.      // repeat for all tvshows
  4184. -    sql = "select * from tvshowview";
  4185. +       sql = VIDEO_DATABASE_VIEW_TVSHOW;
  4186.      m_pDS->query(sql.c_str());
  4187.  
  4188.      total = m_pDS->num_rows();
  4189. @@ -7102,7 +7109,7 @@
  4190.                CLog::Log(LOGERROR, "%s: TVShow season thumb export failed ('%s' -> '%s')", __FUNCTION__, cachedThumb.c_str(), savedThumb.c_str());
  4191.          }
  4192.        }
  4193. -      
  4194. +
  4195.        // now save the episodes from this show
  4196.        sql = FormatSQL("select * from episodeview where idShow=%i order by strFileName, idEpisode",tvshow.m_iDbId);
  4197.        pDS->query(sql.c_str());
  4198. Index: xbmc/VideoDatabase.h
  4199. ===================================================================
  4200. --- xbmc/VideoDatabase.h    (revision 30970)
  4201. +++ xbmc/VideoDatabase.h    (working copy)
  4202. @@ -296,6 +296,7 @@
  4203.  
  4204.    CVideoDatabase(void);
  4205.    virtual ~CVideoDatabase(void);
  4206. +  virtual bool Open();
  4207.  
  4208.    virtual bool CommitTransaction();
  4209.  
  4210. Index: xbmc/ViewDatabase.cpp
  4211. ===================================================================
  4212. --- xbmc/ViewDatabase.cpp   (revision 30970)
  4213. +++ xbmc/ViewDatabase.cpp   (working copy)
  4214. @@ -22,12 +22,14 @@
  4215.  #include "stdafx.h"
  4216.  #include "ViewDatabase.h"
  4217.  #include "Util.h"
  4218. +#include "FileSystem/SpecialProtocol.h"
  4219. +#include "Settings.h"
  4220.  #include "ViewState.h"
  4221.  
  4222.  //********************************************************************************************************************************
  4223.  CViewDatabase::CViewDatabase(void)
  4224.  {
  4225. -  m_strDatabaseFile = VIEW_DATABASE_NAME;
  4226. +  m_strDefaultDatabaseName = VIEW_DATABASE_NAME;
  4227.  }
  4228.  
  4229.  //********************************************************************************************************************************
  4230. @@ -35,6 +37,10 @@
  4231.  {
  4232.  
  4233.  }
  4234. +bool CViewDatabase::Open()
  4235. +{
  4236. +  return CDatabase::Open();
  4237. +}
  4238.  
  4239.  //********************************************************************************************************************************
  4240.  bool CViewDatabase::CreateTables()
  4241. Index: xbmc/ViewDatabase.h
  4242. ===================================================================
  4243. --- xbmc/ViewDatabase.h (revision 30970)
  4244. +++ xbmc/ViewDatabase.h (working copy)
  4245. @@ -21,7 +21,7 @@
  4246.   */
  4247.  #include "Database.h"
  4248.  
  4249. -#define VIEW_DATABASE_NAME "ViewModes.db"
  4250. +#define VIEW_DATABASE_NAME "ViewModes"
  4251.  
  4252.  class CViewState;
  4253.  
  4254. @@ -30,6 +30,7 @@
  4255.  public:
  4256.    CViewDatabase(void);
  4257.    virtual ~CViewDatabase(void);
  4258. +  virtual bool Open();
  4259.  
  4260.    bool GetViewState(const CStdString &path, int windowID, CViewState &state);
  4261.    bool SetViewState(const CStdString &path, int windowID, const CViewState &state);
Advertisement
Add Comment
Please, Sign In to add comment