Friday, April 29, 2011

MySQL AND Filemaker Pro?

Hi All,

I have a client that wants to use Filemaker for a few things in their office, and may have me building a web app.

The last time I used, or thought about, or even heard of, Filemaker was about 10 years ago, and I seem to remember that I don't want to use it as the back end of a sophisticated web app, so I am thinking to try to sell them on MySQL.

However, will their Filemaker database talk to MySQL? Any idea how best to talk them down from Filemaker?

From stackoverflow
  • You may have a hard time talking them out of FileMaker, because it was actually a pretty clever tool for making small, in-house database applications, and it had a very loyal user base. But you're right--it's not a good tool for making a web application.

    I had a similar problem with a client who was still using a custom dBase IV application. Fortunately, Perl's CPAN archive has modules for talking to anything. So I wrote a script that exported the entire dBase IV database every night, and uploaded it into MySQL as a set of read-only tables.

    Unfortunately, this required taking MySQL down for 30 minutes every night. (It was a big database, and we had to convert free-form text to HTML.) So we switched to PostgreSQL, and performed the entire database update as a single transaction.

    But what if you need read-write access to the FileMaker database? In that case, you've got several choices, most of them bad:

    1. Build a bi-directional synchronization tool.
    2. Get rid of FileMaker entirely. If the client's FileMaker databases are trivial, this may be relatively easy. I'd begin by writing a quick-and-dirty clone of their most important databases and demoing it to them in a web browser.
    3. The client may actually be best served by a FileMaker-based web application. If so, refer them to Google.

    But how do you sell the client on a given choice? It's probably best to lay out the costs and benefits of each choice, and let the client decide which is best for their business. You might lose the job, but you'll maintain a reputation for honest advice, and you won't get involved in a project that's badly suited to your client.

  • I've been tackling similar problems and found a couple of solutions that emk hasn't mentioned...

    1. FileMaker can link to external SQL data sources (ESS) so you can use ODBC to connect to a MySQL (or other) database and share data. You can find more information here. we tried it and found it to be pretty slow to be honest
    2. Syncdek is a product that claims to allow you to perform data replication and data transmission between Filemaker, MySQL and other structured sources.
    3. It is possible to use Filemaker's Instant Web Publishing as a web service that your app can then push and pull data through. We found a couple of wrappers for this in python and php
    4. you can put a trigger in the FileMaker database so that every time a record is changed (or part of a record you are interest in) you can call a web service that updates a MySQL or memcached version of that data that your website can access.

    I found that people like FileMaker because it gives them a very visual interface onto their data - it's very easy to make quite large self-contained applications without too much development knowledge. But, when it comes to collaboration with many users or presenting this data in a format other than the FileMaker application we found performance a real problem.

  • We develop solutions with both FileMaker and PHP/MySQL. Our recommendation is to do the web app in a web app optimised technology like MySQL.

    Having said that, FileMaker does have a solid PHP API so if the web app has relatively lightweight demands (e.g. in house use) then use that and save yourself the trouble of synchronisation.

    FileMaker's ESS technology let's FileMaker use an SQL db as the backend data source, which gives you 2 options:

    1. Use ESS as a nice tight way to synchronise right within FileMaker - that way you'd have a "native" data source to work with within the FileMaker solution per se.

    2. Use ESS to allow FileMaker to be used as a reporting/data mining/casual query and edit tool directly on the MySQL tables - it works sweet.

    We've found building a sophisticated application in FileMaker with ESS/MySQL backend to be very tricky, so whether you select 1 or 2 from above depends on how sophisticated and heavy duty that FileMaker usage is.

    Otherwise, SyncDek has a good reputation as a third party solution for automating Synchronisation.

Detecting when Iframe content has loaded (Cross browser)

I'm trying to detect when an iframe and its content have loaded but not having much luck. My application takes some input in text fields in the parent window and updates the iframe to provide a 'live preview'

I started with the following code (YUI) to detect when the iframe load event occurs.

$E.on('preview-pane', 'load', function(){
    previewBody = $('preview-pane').contentWindow.document.getElementsByTagName('body')[0];
}

'preview-pane' is the ID of my iframe and I'm using YUI to attach the event handler. However, trying to access the body in my callback (upon iframe load) fails, I think because the iframe loads before the event handler is ready. This code works if I delay the iframe loading by making the php script that generates it sleep.

Basically, I'm asking what is the correct approach across browsers to detect when the iframe has loaded and its document is ready?

From stackoverflow
  • See this blog spot. It uses jQuery, but it should help you even if you are not using it.

    David Caunt : Interesting, but the problem I have is with the load events and timing. I am listening for the load event as advised by that article.
  • to detect when the iframe has loaded and its document is ready?

    It's ideal if you can get the iframe to tell you itself from a script inside the frame. For example it could call a parent function directly to tell it it's ready. Care is always required with cross-frame code execution as things can happen in an order you don't expect. Another alternative is to set ‘var isready= true;’ in its own scope, and have the parent script sniff for ‘contentWindow.isready’ (and add the onload handler if not).

    If for some reason it's not practical to have the iframe document co-operate, you've got the traditional load-race problem, namely that even if the elements are right next to each other:

    <img id="x" ... />
    <script type="text/javascript">
        document.getElementById('x').onload= function() {
            ...
        };
    </script>
    

    there is no guarantee that the item won't already have loaded by the time the script executes.

    The ways out of load-races are:

    1. on IE, you can use the ‘readyState’ property to see if something's already loaded;

    2. if having the item available only with JavaScript enabled is acceptable, you can create it dynamically, setting the ‘onload’ event function before setting source and appending to the page. In this case it cannot be loaded before the callback is set;

    3. the old-school way of including it in the markup:

      <img onload="callback(this)" ... />

    Inline ‘onsomething’ handlers in HTML are almost always the wrong thing and to be avoided, but in this case sometimes it's the least bad option.

    David Caunt : Thanks. My solution checks the readyState (if exists), then the body elements innerHTML length to see if it has loaded. If not, attaches the load event handler. Seems to work ok

What's a good brief introduction to Mono/.NET programming?

Hello, I am quite impressed by the Mono features, especially by the portability of the library. I think I'll give it a try soon or later and I'd need some directions to find an introduction to Mono/.NET programming. Can you help me?

Thank you

From stackoverflow
  • Mostly Mono programming is not any different classical .NET programming.

    You can only use C# in a decent way, non of the other .NET languages. Even though Mono claims VB.NET support it's far from being a reasonable compiler or reasonable IL support. VB.NET mostly experimental.

    If your main OS is Windows easiest way to start downloading the Mono VmWare - http://www.go-mono.com/mono-downloads/download.html - openSuse

    Enviroment is ready kick start Mono development.

    Try Mono Start page for tips

    Don't forget you can't use COM.

    Best way to proceed code it in Mono (IDE is terrible after VS.NET) then porting it Windows.

    jpobst : Although you cannot use COM, you can use the winforms WebBrowser Control, which is implemented using Mozilla's Gecko. VB.Net is unfortunately still at the VB.Net 8 version, not the VB.Net 9 version.
    dr. evil : @jpobst I didn't know WebBrowser Control implementation, that's kind of cool :) VB.NET 8 version is not the problem the problem is compiler is seriously bad and support VB DLLs is a bit flaky. You can't code in compiler if it gives an "Unknown Error" without a line number!
    jpobst : Ah, that would suck. I did not know the VB.Net compiler was that bad. On the plus side, you can compile with MS's VB compiler and use that on Mono. However, that will not get you around missing stuff in the VB support dll.
    dr. evil : I really love the idea of Mono, it's such a hard job and quite impressive. Don't want to disrespect the developers. So I keep my hopes high :) Hopefully they'll fix those show stoppers soon.
  • I found Petzold's free ebook .NET Book Zero useful as an introduction to .Net programming.

  • Great Recommendations by Slough. I've found the Mono Getting Started Guide and the Wikipedia page very helpful in understanding it's history, how it works, and how to get started:

Overload "base" contructor or "this" contructor?

I have few types that derive from simplified Base as shown below.

I am not sure whether to use base class's constructor or this constructor when overloading constructors.

ConcreteA overloads constructors purely using base constructors, while
ConcreteB overloads using this for the first two overloads.

What would be a better way of overloading constructors?

public abstract class Base
{
    public string Name { get; set; }
    public int? Age { get; set; }

    protected Base() : this(string.Empty) {}
    protected Base(string name) : this(name, null) {}
    protected Base(string name, int? age)
    {
        Name = name;
        Age = age;
    }
}

public class ConcreteA : Base
{
    public ConcreteA(){}
    public ConcreteA(string name) : base(name) {}
    public ConcreteA(string name, int? age) : base(name, age)
    {
    }
}

public class ConcreteB : Base
{
    public ConcreteB() : this(string.Empty, null){}
    public ConcreteB(string name): this(name, null){}
    public ConcreteB(string name, int? age) : base(name, age)
    {
    }
}

[Edit] It looks like what Ian Quigley has suggested in his answer seemed to make sense. If I were to have a call that initialize validators, ConcreteA(string) will never initialize validators in following case.

public class ConcreteA : Base
{
    public ConcreteA(){}
    public ConcreteA(string name) : base(name) {}
    public ConcreteA(string name, int? age) : base(name, age)
    {
        InitializeValidators();
    }
    private void InitializeValidators() {}
}
From stackoverflow
  • In your case from what you have provided it doesn't matter. You really only want to use this when you have a constructor in your current class that is not part of your base class, or if there is some code in the current class constructor that you want to execute that isn't contained in the base class.

  • This. Because if you ever place code in ConcreteB(string, int?) then you want the string only constructor to call it.

    Sung Meister : This seems to make sense if I were to have other initializations going on in concrete constructors.
    Dead account : Yes, and "this" will always call "base" at the end of the day. So even if "this" does nothing, it'll drop down to "base"
  • In general, I'd call "this" rather than "base". You'll probably reuse more code that way, if you expand your classes later on.

  • In order to reduce the complexity of the code paths, I usually try to have exactly one base() constructor call (the ConcreteB case). This way you know that the initialization of the base class always happens in the same fashion.

    However, depending on the class you override, this may not be possible or add unneeded complexity. This holds true for special constructor patterns such as the one when implementing ISerializable.

  • It is fine to mix and match; ultimately, when you use a this(...) constructor, it will eventually get to a ctor that calls base(...) first. It makes sense to re-use logic where required.

    You could arrange it so that all the constructors called a common (maybe private) this(...) constructor that is the only one that calls down to the base(...) - but that depends on whether a: it is useful to do so, and b: whether there is a single base(...) ctor that would let you.

  • Ask yourself again why you are overloading the constructor in the Base class? This one is enough:

    protected Base()
    

    Same goes for the subclass unless you need either fields to have a particular value when you instantiate which in your example is not the case since you already have the default constructor.

    Also remember that any constructor should put the instance of the object in a correct state.

Implementing variable constraints in C++

I've been looking for an example that shows how to implement constraints in C++ (or a boost library that lets me do this easily), but without much luck. The best I could come up with off the top of my head is:

#include <boost/function.hpp>
#include <boost/lambda/lambda.hpp>

template<typename T>
class constrained
{
    public:
     constrained(boost::function<bool (T)> constraint, T defaultValue, T value = defaultValue)
     {
      ASSERT(constraint(defaultValue));
      ASSERT(constraint(value));

      this->value = value;
      this->defaultValue = defaultValue;   
      this->constraint = constraint;      
     }

     void operator=(const T &assignedValue)
     {
      if(constraint(assignedValue))
       value = assignedValue;  
     } 

    private:
     T value;
     T defaultValue;
     boost::function<bool (T)> constraint;
};

int main(int argc, char* argv[])
{
    constrained<int> foo(boost::lambda::_1 > 0 && boost::lambda::_1 < 100, 5, 10);

    foo = 20; // works
    foo = -20; // fails

    return 0;
}

Of course there's probably some more functionality you'd want from a constraint class. This is just an idea for a starting point.

Anyway, the problem I see is that I have to overload all operators that T defines in order to make it really behave like a T, and there is no way for me to find out what those are. Now, I don't actually need constraints for that many different types, so I could just leave out the template and hard code them. Still, I'm wondering if there's a general (or at least more succint/elegant) solution or if there's anything seriously wrong with my approach.

From stackoverflow
  • I might just be confused, but if you are facing parameters that must not violate specific constraints, wouldn't it be easiest to create a class for them, checking for constraints in constructors and assignment operators?

    drby : I could do that of course, but I have lots of different parameters with lots of different constraints, so the result would be a lot of brittle boilerplate code. In the above solution, all the logic is in a single variable declaration. I'd say that's better.
  • Looks good as for tiny example. But be sure to implement all the operators and handle somehow wrong values.

    foo = 100; // works
    ++foo; // should throw an exception or perform an assert
    

    Use boost operators to help you with operators overload.

    And probably it would be good to have an option as a template parameter: either exception or assertion.

    I'd use such class. It is always better to have an index parameter that auto check vector range and do assertion.

    void foo( VectorIndex i );
    
    DevSolar : "It is always better to have an index parameter that auto check vector range and do assertion." - how about at()?
    Mykola Golubyev : @DevSolar: a) at() throws an exception; b) such VectorIndex can be implemented for any legacy Array in the project.
  • I agree with Mykola Golubyev that boost operators would help.

    You should define all the operators that you require for all the types you are using.

    If any of the types you are using don't support the operator (for example the operator++()), then code that calls this method will not compile but all other usages will.

    If you want to use different implementations for different types then use template specialisation.

  • You don't need to overload all operators as others have suggested, though this is the approach that offers maximum control because expressions involving objects of type constrained<T> will remain of this type.

    The alternative is to only overload the mutating operators (=, +=, -=, *=, /=, %=, &=, |=, ^=, <<=, >>=, pre and post ++, pre and post --) and provide a user-defined conversion to T:

    template<typename T>
    class constrained {
        ... // As before, plus overloads for all mutating operators
    public:
        operator T() const {
            return value;
        }
    };
    

    This way, any expression involving a constrained<T> object (e.g. x + y where x is int and y is constrained<int>) will be an rvalue of type T, which is usually more convenient and efficient. No safety is lost, because you don't need to control the value of any expression involving a constrained<T> object -- you only need to check the constraints at a time when a T becomes a constrained<T>, namely in constrained<T>'s constructor and in any of the mutating operators.

  • Boost.Constrained_Value may be of interest to you. It was reviewed last December, but it is not in the latest Boost release. IIRC, the review was mostly positive, but the decision is still pending.

  • Boost actually had such a library under discussion (I don't know what became of it). I've also written my own version of such a type, with slightly different behaviour (less flexible, but simpler). I've blogged an admittedly somewhat biased comparison here: Constrained vs. restricted value types

    Edit: apparently Eric knows better what happened to boost's implementation.

How do I get the server endpoint in a running flex application?

I need a way of getting the active server address, port, and context during runtime from my flex application. Since we are using ant for our build process, the server connection information is dynamically specified in our build properties file, and the {server.name}, {server.port} and {context.root} placeholders are used in the services-config.xml file instead the actual values.

We have some other Java servlets running on the same machine as our blazeDS server, and I'd like some way to programmatically determine the server endpoint information so I don't need to hardcode the servlet URL's into an XML file (which is what we are presently doing).

I have found that I can at least get the context root by adding the following to our main application MXML file:

<mx:Application ... >
  <mx:HTTPService id="contextRoot" rootURL="@ContextRoot()"/>
</mx:Application>

However, I still need some way of fetching the server address and port, and if I specify the entire address by giving -context-root=http://myserver.com:8080/mycontext, then the flex application attempts to connect to http://localhost/http://myserver.com:8080/mycontext/messagebroker/amf, which is of course totally wrong. What is the proper way to specify the context root and server URL, and how can I retrieve them from our application?

From stackoverflow
  • Why not call a javascript function in the wrapper via ExternalInterface to return the value of location.hostname?

    <mx:Script>
        <![CDATA[
            private var hostname:String;
    
            private function getHostName():void
            {
                hostname = ExternalInterface.call(getHostName);
            }
        ]]>
    </mx:Script>
    

    javascript in wrapper:

    <script type="text/javascript">
        function getHostName()
        {
            return location.hostname;
        }
    </script>
    
    Nik Reiman : That's not what I'm asking. Plus, you can get this just as easily through Application.application.url and parsing the string.
  • You can use the BrowserManager to get the information about the url.

    var bm:IBrowserManager = BrowserManager.getInstance();
    bm.init(Application.application.url);
    var url:String = bm.base;
    

    see also http://livedocs.adobe.com/flex/3/html/deep_linking_7.html#251252

  • We use an Application subclass that offers the following methods :

     /**
      * The URI of the AMF channel endpoint. <br/>
      * Default to #rootURI + #channelEndPointContext + #this.channelEndPointPathInfo
      */
     public function get channelEndPointURI() : String
     {
        return this.rootServerURI + ( this.channelEndPointContext ? this.channelEndPointContext : "" ) + this.channelEndPointPathInfo
     }
    
     /**
      * The root URI (that is scheme + hierarchical part) of the server the application
      * will connect to. <br/>
      * If the application is executing locally, this is the #localServerRootURI. <br/>
      * Else it is determined from the application #url. <br/>
      */ 
     public function get rootServerURI() : String
     {
          var result : String = ""
          if ( this.url && ( this.url.indexOf("file:/") == -1 ) )
          {
               var uri : URI = new URI( this.url )
               result = uri.scheme + "://" + uri.authority + ":" + uri.port
          }
          else
          {
               result = this.localServerRootURI
          }
    
          return result 
     }
    

    This generic application supports the channelEndPointContext, channelEndPointPathInfo and localServerRootURI properties (typically "mycontext" and "/messagebroker/amf/" in your example, the local server root being used when the application is executed via Flex Builder, in such cases it has a file:// URL).
    The determination of the complete endpoint URI is then performed using either the localServerRootURI property or using the application url as our services are exposed by the very same server that serves the application's SWF (which is, as far as I understand your case too).

    So, in your example, one would write :

     <SuperApplication ...> <!-- SuperApplication is the enhanced Application subclass -->
        <mx:HTTPService id="myHTTPService" url="{this.channelEndPointURI}"/>
     </SuperApplication>
    

    Starting from here, one can also automatically determine the channelEndPointContext from the application URL instead of hardcoding it as shown in this example.

  • I've used FlashVars to pass urls in before with success. In your template html:

    var rootURL = location.href.substring(0,location.href.indexOf("flexBin"));    
    ...
    
    AC_FL_RunContent(
        "src", "${swf}",
        "FlashVars", "rootURL="+rootURL,
        "width", "${width}",
    ...
    

    And then in flex:

    service.rootURL = Application.application.parameters.rootURL;
    

    The nice thing is you can really pass in whatever you like from the server this way.

ensure two char arrays are not the same

I am randomly generating a grid of characters and storing it in a char[,] array ...

I need a way to ensure that i haven't already generated a grid before serializing it to a database in binary format...what is the best way to compare two grids based on bytes? The last thing i want to do is loop through their contents as I am already pulling one of them from the db in byte form.

I was thinking checksum but not so sure if this would work.

char[,] grid = new char[8,8];
char[,] secondgrid = new char[8,8];//gets its data from db
From stackoverflow
  • From what I can see, you are going to have to loop over the contents (or at least, a portion of it); there is no other way of talking about an arrays contents.

    Well, as a fast "definitely not the same" you could compute a hash over the array - i.e. something like:

        int hash = 7;
        foreach (char c in data) {
            hash = (hash * 17) + c.GetHashCode();
        }
    

    This has the risk of some false positives (reporting a dup when it is unique), but is otherwise quite cheap. Any use? You could store the hash alongside the data in the database to allow fast checks - but if you do that you should pick your own hash algorithm for char (since it isn't guaranteed to stay the same) - perhaps just convert to an int, for example - or to re-use the existing implementation:

        int hash = 7;
        foreach (char c in data) {
            hash = (hash * 17) + (c | (c << 0x10));
        }
    


    As an aside - for 8x8, you could always just think in terms of a 64 character string, and just check ==. This would work equally well at the database and application.

  • I'd go with a checksum/hash mechanism to catch a large percentage of the matches, then do a full comparison if you get a match.

    What is the range of characters used to fill in your grid? If you're using just letters (not mixed case, or case not important), and an 8x8 grid, you're only talking about 7 or so possible collisions per item within your problem space (a very rare occurence) assuming a good hashing function. You could do something like:

    1. Generate Grid
    2. Load any matching grids from DB
    3. if found match from #2, goto 1
    4. Use your new grid.
  • Can't you get the database to do it? Make the grid column UNIQUE. Then, if you need to detect that you've generated a duplicate grid, the method for doing this might involve checking the number of rows affected by your operation, or perhaps testing for errors.

    Also, if each byte is simply picked at random from [0, 255], then performing a hash to get a 4-byte number is no better than taking the first four bytes out of the grid. The chance of collisions is the same.

    Marc Gravell : Since this is a char[] (not byte[]), you'd only have time for 2 characters... using a hash algorithm will make better use if the used/unused code-point ranges, and will (in typical use) give a better collision rate than just taking the first two chars.
    Artelius : Well, my unknowledge of C# shines through. But my first point still stands.
  • Try this (invoke ComputeHash for every matrix and compare the guids):

    private static MD5 md5 = MD5.Create();
    public static Guid ComputeHash(object value)
    {
        Guid g = Guid.Empty;
        BinaryFormatter bf = new BinaryFormatter();
        using (MemoryStream stm = new MemoryStream())
        {
            bf.Serialize(stm, value);
            g = new Guid(md5.ComputeHash(stm.ToArray()));
            stm.Close();
        }
        return g;
    }
    

    note: Generating the byte array might be accomplished a lot simpler since you have a char array.