logo logo

 Back to main page

The NWNX Community Forum

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Off Topic Question: Blob Fields

 
Post new topic   Reply to topic    nwnx.org Forum Index -> Windows technical support
View previous topic :: View next topic  
Author Message
Blacksting



Joined: 03 Jan 2005
Posts: 107

PostPosted: Sat Feb 19, 2005 10:46    Post subject: Off Topic Question: Blob Fields Reply with quote

I am developing a tool in C# to transfer NWN resources through MySQL to my server. I am having a mind numbing problem with blob fields, however, and figured I might toss it out here.

This is my function and everything works fine except the named parameters.
Code:

private void DoResourceTransfer()
      {
          if (DB1.State == 0)
          DB1.Open();
        FileInfo fi;
        FileStream fs;
        BinaryReader br;
        string query;
        byte[] rfile;
         foreach (string filename in ResourceTransferFiles.CheckedItems)
         {
           fi = new FileInfo(ResourcePath+filename);
           if (!fi.Exists)
            fi = new FileInfo(ResourceBackup+filename);
          
            if (fi.Exists)
            {
               
               fs = new FileStream(fi.DirectoryName + "/" + filename, FileMode.Open, FileAccess.Read);
               br = new BinaryReader(fs);
               rfile = br.ReadBytes((int)fs.Length);
               query = "insert into resource_transfer (id,resource) values('" + filename + "',@f)";
               MySqlCommand write = new MySqlCommand(query,DB1);
               write.Parameters.Add("@f",MySqlDbType.MediumBlob,rfile.Length).Value = rfile;
               write.ExecuteNonQuery();
               br.Close();
               fs.Close();
               
            }
            
         }
           DB1.Close();      
      }


Now before we start down the obvious road the documentation for the .Net MySQL connector says it supports named parameters (which I guess could be false.) In any case all fields I try to use a name parameter in (for example I tried values(@fname,@f) all parameters ended up null. This led me to realized that it was not the byte reader or byte array that had the problem (the byte array was the proper length and filled... I checked.) It was the named parameters not correctly transfering data. Secondly I tried the values(?,?) approach but I could not get a Parameters.Add(new MySqlParamter("",filename) to work either. It would crash with an index out of bounds (the null string... it would not accept it.) I am totally stumped. I tried using % as the named parameter switch and that failed as well. I spent an entire night trying the "easy" way to get a blob field going in C# and failed miserably. I would have been better off doing it the hard way... but I have no idea what the hard way would be in C#.


Last edited by Blacksting on Sat Feb 19, 2005 19:33; edited 1 time in total
Back to top
View user's profile Send private message
NoMercy



Joined: 03 Jan 2005
Posts: 123
Location: UK

PostPosted: Sat Feb 19, 2005 14:14    Post subject: Reply with quote

For the love of cheese biscuits, please use the [code]...[/code] things, makes life so much more readable :)

I don't know c# or the API (it might do these things for you) But... have you got quotes around your blob? And does it auto-escape any which appear in it.
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Blacksting



Joined: 03 Jan 2005
Posts: 107

PostPosted: Sat Feb 19, 2005 19:32    Post subject: Reply with quote

The method above is supposed to be a complete binary method and does not require replacing of problematic characters. Anyway, when I tested using the parameter on just the filename portion the string came up null as well so it is definitely a parameter definition issue. The overall question is how to get a blob field in to the database in C# (as all other fields can just be represented in the query directly without problem.) All the examples on the net use ODBC examples which for the most part are directly translatable in to MySql.Data.dll examples..... except the parameters dont work.
Back to top
View user's profile Send private message
Blacksting



Joined: 03 Jan 2005
Posts: 107

PostPosted: Sat Feb 19, 2005 21:52    Post subject: Reply with quote

When all else fails find out how the hackers do it Smile

For anyone that cares there was an easier way than the "easy" way.
Code:

string path = ResourcePath;
        foreach (string filename in ResourceTransferFiles.CheckedItems)
         {
           FileInfo fi = new FileInfo(ResourcePath+filename);
           if (!fi.Exists)
           {
              path = ResourceBackup;
              fi = new FileInfo(ResourceBackup+filename);
           }
          
            if (fi.Exists)
            {
               
               string query = "insert into resource_transfer (id,resource) values('" + filename + "',load_file('" + path + "/" + filename + "'))";
               query.Replace("\\","/");
               MySqlCommand swrite = new MySqlCommand(query,DB1);
                           }
            
         }
Back to top
View user's profile Send private message
Blacksting



Joined: 03 Jan 2005
Posts: 107

PostPosted: Sat Feb 19, 2005 23:17    Post subject: Reply with quote

On to the next step in my application. Now that the resource file has been transferred to the server in a blob field I am going to use "into dumpfile" to get it to the resource folder there. Unfortunately into dumpfile has no overwrite feature. That means any resources being transferred to the destination folder can't exist. I am trying to write a C++ or C# dll and call it from MySQL which is now apparently possible. Unfortunately I can't get MySQL to recognize any functions. Has any MySQL guru here done any work with CREATE FUNCTION using C++ dlls?
Back to top
View user's profile Send private message
Blacksting



Joined: 03 Jan 2005
Posts: 107

PostPosted: Sun Feb 20, 2005 1:42    Post subject: Reply with quote

Ok I guess I am stepping back one step. I figured it would be an easy thing to transfer data between my local MySQL database and the server MySQL database. I figured there was an inherent MySQL command to transfer data from different hosts. Unfortunately no such command seems to exist.... and I have to go back to finding a way to populate a blob field with parameters.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Windows technical support All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group