title: Delphi: executing SQL queries on MemTable or other type of Dataset
body: <p>I am using Firedac to create SQL Lite connection on a local .db file. I am using:</p>
  
  <ul>
  <li>TFDConnection: to create the connection object</li>
  <li>TFDQuery: to execute my SQLite queries.</li>
  </ul>
  
  <p>What I want is copy all data or tables from my SQLite database file on memory and then execute SQL queries on it.</p>
  
  <p>I've read that I can use mMemTable or other datasets but all information regarding this is more confusing than helping me out.</p>
  
  <p>I want to achieve this because I have to run "heavy" queries (thousands of queries inside a for-loop) but without sacrificing so much speed and resources. Currently I have 5 query.open("SELECT * ....") inside a very big loop, making my code very slow. I suppose this derives from many query.open() stuff.</p>
  
  <p>If I have a copy of my SQLite data on memory and then run queries on that dataset, it would increase my code speed drastically. </p>
  
  <p>I have implemented this on another part of my code, where I used limited amount of data taken from SQLite file inside sorted lists, and then I iterated over my lists. Performance increased over 300% after replacing query.open() inside that big loop.</p>
  
  <p>I cannot use the same method as mentioned above, because I want to run SQL queries from my "SQL in Memory" to fetch specific data with complex criteria.</p>
  
  <p>So anyone can help me out with the above issue? Maybe a small and "clear" tutorial regarding this?</p>
  
  <hr>
  
  <p>It seems that my question is still not answered. I will try to be more specific with another example of code in order to understand the situation. I am still trying to achieve what I was telling above. I want to copy data from my SQLite database on memory, DISCONNECT and then run SQLite queries on in memory database. It is supposed to work with TFDQuery, TFDLocalSQL, TFDConnection.</p>
  
  <p>I am creating and fetching data from SQL file using "conn" connection and "query". Then I activate </p>
  
  <pre><code>try
     // connection with local SQL file to fetch data from
     query.Connection := conn;
     query.Open('SELECT * FROM CAMPAIGNS');
     query.FetchAll();
     // I've put SQL text because FDQuery1 must me active and SQL text must be 
     // included
     FDQuery1.SQL.Text:='SELECT 1';
     FDQuery1.Active:= true;
     // the following line of code, is supposed to copy data and structure
     FDQuery1.CloneCursor(query,true,true);
  finally
     conn.Close();
     query.Free();
     conn.Close();
  end;
  // it seems from showmessage that records exist inside TFDQuery
  showmessage(FDQuery1.RecordCount.ToString);
  // when I execute the following query, it tells that such table does not 
  // exist
  FDQuery1.Open('SELECT * FROM CAMPAIGNS');
  </code></pre>