Fetching database from MySQL to SQLite - mysql

I am trying to complete an iPhone app. And for this i need to fetch a database from MySQL to SQLite. For this case i did use some code like bellow-
MCPConnection *theConnec;
MCPResult *theRes;
//initialize connection string vars
NSString *dbURL = #"XXXXXX";
NSString *userName = #"XXXXXX";
NSString *pass = #"XXXXXX";
//open connection to database
theConnec = [theConnec initToHost:dbURL withLogin:userName password:pass usingPort:3306];
//NSLog(#"The connection to database was successfull");
[theConnec selectDB:#"XXXXXX"];
//{
// NSLog(#"Database found");
//}
//else
//{
// NSLog(#"Database not found");
//}
theRes = [theConnec queryString:#"select * from seahawk_tag"];
//get the number of rows
NSInteger numberOfRows = [theRes numofRows];
NSLog(#"Query of MySQL Database %#", numberOfRows);
return NSApplicationMain(argc, (const char **) argv);
[theConnec release];
But this code does not work properly. Here also mention that i have used some framework like cocoa.framework, cocos2d, openGLES.framework, openAL.framework, APPKit.framework, MCPKit.framework, Quartzcore.framewrok .
and finally i get an error msg that CIColer.h is missing.
freinds, if u know the solution or if u have another code then pls help me

Are you asking how to poll a remote database, or how to pre-export?
Polling a remote database and importing data should be as simple as opening the socket to the remote db, executing the query, and closing again.

Related

Qt & MySQL first connections fail

I using Qt 5.15 and I make a standard connection to MySQL
bool open() {
QMutexLocker ml(&fMutex);
fDatabaseNumber = QString::number(++fDatabaseCounter);
fSqlDatabase = QSqlDatabase::addDatabase("QMYSQL", fDatabaseNumber);
fSqlDatabase.setHostName(host);
fSqlDatabase.setDatabaseName(schema);
fSqlDatabase.setUserName(username);
fSqlDatabase.setPassword(password);
if (!fSqlDatabase.open()) {
qDebug() << fSqlDatabase.lastError().databaseText();
return false;
}
fQuery = new QSqlQuery(fSqlDatabase);
return true;
}
Like usually :). I call this code from 10 different threads at same time. And always several of the first connections to database fails with "Can't connect to MySQL server on '127.0.0.1'" message. All of next connections successful, no mater how many connections threads make at the time. I don't know, what I'm doing wrong.

Migrating MySQL blob (image) to FileMaker container using PowerShell

In searching I've found a number of other people that have tried, but none that have been successful.
Here's the problem. I want to take a bunch of images I have stored on my MySQL server in blobs and move them into FileMaker containers.
The best lead I've got is the putas command. It looks something like putas ('$Image','JPEG').
My particular application is as follows. $DataSet.Image1 is a JPEG file stored as "0xFFD8....". The data being in this format may well be the issue, but I don't know what I'd need to convert it to first.
$cmd.CommandText = "update Checklists set Image1 = PutAs('$($DataSet.Image1)', 'JPEG')"
$cmd.ExecuteNonQuery();
All I keep getting is syntax error, but I've tried the syntax many different ways I can't get it to go no matter what I do.
I'd very much like to see someone having success with this to post their example. Any other ideas or workarounds are welcome as well.
Edit:
Here is some extra info. Greg Lane at Skeleton Key gives this example, but I'm not sure how to translate it to PowerShell.
import java.sql.*; import java.io.*;
def url = "jdbc:filemaker://localhost/fmserver_sample";
def driver = "com.filemaker.jdbc.Driver";
def user = "admin";
def password = "";
System.setProperty("jdbc.drivers", driver);
connection = DriverManager.getConnection (url, user, password);
filename = "/Users/Greg/Pictures/vacation/DSC_0202.jpg";
file = new File (filename);
inputstream = new FileInputStream (filename);
sql = "INSERT INTO english_nature (ID, img) VALUES (-1, PutAs(?, 'JPEG'))";
pstatement = connection.prepareStatement ( sql );
pstatement.setBinaryStream (1, inputstream, (int)file.length ());
pstatement.execute ();
//cleanup
pstatement = null;
inputstream = null;
file = null;
connection.close();
I figured it out. For anyone in the future here is how you do it.
$cmd.CommandText = "update Checklists set Image1 = PutAs(?, 'JPEG') where serial = '$($DataSet.serial)' AND ChecklistNumber = 1"
$cmd.Parameters.Add('?', $DataSet.Image1)
$cmd.Prepare()
$cmd.ExecuteNonQuery();

System.Data.OleDb.OleDbException: Invalid path or file name

i have the following code which has been getting me data from flat files. but now all of a sudden i am getting this error
System.Data.OleDb.OleDbException: Invalid path or file name
but the code hasnt changed it worked for months,im not sure what went wrong.
System.Web.Script.Serialization.JavaScriptSerializer json = new System.Web.Script.Serialization.JavaScriptSerializer();
string jsonText;
System.Collections.Generic.List<object> objList = new List<object>();
string strConn = #"Provider=vfpoledb;Data Source=\\10.0.0.0\wwwroot\apps\assembly\FlatDatabaseDbfs\vt_Flat.dbf;Collating Sequence=machine;";
using (System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(strConn))
{
System.Data.OleDb.OleDbCommand cmddbf = new System.Data.OleDb.OleDbCommand();
cmddbf.Connection = conn;
conn.Open();
cmddbf.CommandText = "select * from vt_Flat";
var dr = cmddbf.ExecuteReader();
while (dr.Read())
{
objList.Add(new
{
Code = (dr["dp_code"].ToString().Trim()),
});
};
}
var filteredList = objList.Where(obj => ((dynamic)obj).Status == (Request.QueryString["Status"] ?? "") && ((dynamic)obj).DepCode == (Request.QueryString["Code"] ?? ""));
jsonText = json.Serialize(filteredList);
Response.Write(jsonText);
}
is there something wrong with iis permissions?
Aside from the connection having to point to the PATH as already noted by Oleg, in the C# instances of OleDbConnection I have done in the past, the connection string uses
Provider=VFPOLEDB.1
Don't know if it is case/sensitive issue and the ".1" which is also part of the provider string.
Once you have a valid connection to the PATH, then your query can query from any table within the path location. So if you had 2+ files, and needed to join them, you would do so with a standard query / join. In your case, your command text is only "select *" since you changed your original connection that included the table. Change the command text to
"select * from vt_Flat"
OTHER CONSIDERATIONS
Is this being run from some web service project? If so, THAT could be the basis. You as a developer testing are running with your permissions / access. If running as a web server, the WEB-based user account may not have permissions to the folder to process / work with the data.
Check the folder of your production data to ALLOW the web user if so running. If that doesn't work, set permissions on the folder to EVERYBODY (only for testing/confirmation purposes only). See if that is the problem.
Also, from the Provider connection, did you try with it as all upper case VFPOLEDB.1?
Use path instead of file name, e.g.:
Data Source=\\10.0.0.0\wwwroot\apps\assembly\FlatDatabaseDbfs\;

dynamic SQL execution and saving the result in flat file in SSIS

I want to create a SSIS package which writes a file with data generated by executing a SQL Statement. This generic package will be invoked by other packages passing in correct SQL as a variable.
Thus in the generic package :
I want to execute a dynamic SELECT query and fetch dynamic number of columns from a single database instance, the connection string does not per call and store the result into a flat file.
What would be an ideal way to accomplish this in SSIS.
What I tried :
The simplest solution that I could find was a writing a script task which would open a SQL connection , execute the SQL using SQLCommand, populate a datatable using the data fetched and write the contents directly to the file system using System.io.File and Release the connection.
I tried using OLE Database source with the SQLsupplied by a variable (with Validation set to false) and directing the rows into a Flat file connection. However due to the dynamic number and names of the columns I ran into errors.
Is there a more standard way of achieving this without using a script task?
How about this ... concatenate all field values into one field, and map AllFields to a field in a text file destination.
SELECT [f1]+',' + [f2] AS AllFields FROM [dbo].[A]
All of the "other"packages will know how to create the correct SQL. Their only contract with the "generic" package would be to eventually have only one field nameed "AllFields".
To answer your question directly, I do not think there is a "standard" way to do this. I believe the solution from Anoop would work well and while I have not tested the idea I wish I would have investigated it before writing my own solution. You should not need a script task in that solution...
In any case, I did write my own way to generate csv files from SQL tables that may run up against edge cases and need polishing but works rather well right now. I am looping through multiple tables before this task so the CurrentTable variable can be replaced with any variable you want.
Here is my code:
public void Main()
{
string datetime = DateTime.Now.ToString("yyyyMMddHHmmss");
try
{
string TableName = Dts.Variables["User::CurrentTable"].Value.ToString();
string FileDelimiter = ",";
string TextQualifier = "\"";
string FileExtension = ".csv";
//USE ADO.NET Connection from SSIS Package to get data from table
SqlConnection myADONETConnection = new SqlConnection();
myADONETConnection = (SqlConnection)(Dts.Connections["connection manager name"].AcquireConnection(Dts.Transaction) as SqlConnection);
//Read data from table or view to data table
string query = "Select * From [" + TableName + "]";
SqlCommand cmd = new SqlCommand(query, myADONETConnection);
//myADONETConnection.Open();
DataTable d_table = new DataTable();
d_table.Load(cmd.ExecuteReader());
//myADONETConnection.Close();
string FileFullPath = Dts.Variables["$Project::ExcelToCsvFolder"].Value.ToString() + "\\Output\\" + TableName + FileExtension;
StreamWriter sw = null;
sw = new StreamWriter(FileFullPath, false);
// Write the Header Row to File
int ColumnCount = d_table.Columns.Count;
for (int ic = 0; ic < ColumnCount; ic++)
{
sw.Write(TextQualifier + d_table.Columns[ic] + TextQualifier);
if (ic < ColumnCount - 1)
{
sw.Write(FileDelimiter);
}
}
sw.Write(sw.NewLine);
// Write All Rows to the File
foreach (DataRow dr in d_table.Rows)
{
for (int ir = 0; ir < ColumnCount; ir++)
{
if (!Convert.IsDBNull(dr[ir]))
{
sw.Write(TextQualifier + dr[ir].ToString() + TextQualifier);
}
if (ir < ColumnCount - 1)
{
sw.Write(FileDelimiter);
}
}
sw.Write(sw.NewLine);
}
sw.Close();
Dts.TaskResult = (int)ScriptResults.Success;
}
catch (Exception exception)
{
// Create Log File for Errors
//using (StreamWriter sw = File.CreateText(Dts.Variables["User::LogFolder"].Value.ToString() + "\\" +
// "ErrorLog_" + datetime + ".log"))
//{
// sw.WriteLine(exception.ToString());
//}
Dts.TaskResult = (int)ScriptResults.Failure;
throw;
}
Dts.TaskResult = (int)ScriptResults.Success;

Anonymously Hosted DynamicMethods Assembly

In my mvc web application, I am getting this error:
Anonymously Hosted DynamicMethods Assembly
Stack Trace : at Read_<>f__AnonymousType14(ObjectMaterializer1 ) at System.Data.Linq.SqlClient.ObjectReaderCompiler.ObjectReader`2.MoveNext() at project.com.Concrete.DetailsRepository.GetDetails(String type) in path
Message : The null value cannot be assigned to a member with type System.Int32 which is a non-nullable value type.
When I run my site from local server it is working fine.
But when it runs at remote server it is giving above error
Here is my code:
var res=
(from r in DetailsTable
where r.Activated == true
group r by new { r.ActivationDate, r.ProductID, r.SubProductID } into t
select new { icount = t.Count(),
sActivationDate = t.Key.ActivationDate.ToShortDateString(),
iProductID = t.Key.ProductID,
iSubProductid = t.Key.SubProductID })
.OrderBy(r => r.icount);
Thanks
AS
The issue you're having is that your query is empty on the remote server where data exists on the local server.
I'm not exactly sure at which part in the query the exception is happening, so I'd suggest splitting your query in half.
var res=
from r in DetailsTable
where r.Activated == true;
if(res.Count() == 0)
return; // or handle gracefully as appropriate
var groups =
from r in res
group r by new { r.ActivationDate, r.ProductID, r.SubProductID } into t
select new { icount = t.Count(),
sActivationDate = t.Key.ActivationDate.ToShortDateString(),
iProductID = t.Key.ProductID,
iSubProductid = t.Key.SubProductID })
.OrderBy(r => r.icount);
I'm sure there is a more graceful way of doing this within a single query statement, but without more details I'm not sure exactly how to proceed.