Filemaker Incompatible Types In Assignment

FileMaker 11 has been released and it’s full of great new features. While not the most glamorous, one of my favorite new features is the new FileMaker ODBC drivers. The drivers have been rewritten and are much easier to install and configure on both Windows and Mac OS X. Here’s an example of one of the DSN configuration screens for Mac OS X:

If you’ve struggled with DSN configuration with previous versions of the FileMaker ODBC drivers for Mac OS X, I’m certain you’ll appreciate the beauty of this new version. Also, note that the driver now supports a slow query log, which can be quite useful for troubleshooting performance issues in your application.

Higher Limits

One of FileMaker 10’s most frustrating ODBC limitations was the restrictive limit on the length of SQL queries. Most queries in FileMaker 10 were limited to a few thousand characters. FileMaker 11 supports longer queries and also parameterized queries, which allow very large text or binary data to be inserted into FileMaker fields, if your client supports them.

PHP

The new ODBC drivers work much better with PHP. Here’s a short PHP snippet which shows a few of the features that are now supported, including DSN-less connections and prepared statements:

One of the nice things about using ODBC instead of the FileMaker API for PHP is that an UPDATE like the one shown in this example will happen atomically…either all of the records are updated or none of them are. In this example, if any of the records with a quantity of zero is locked, none of the records will be changed and the odbc_errormsg() function will return:

[FileMaker][FileMaker ODBC] (301): Record is locked by another user

Accomplishing the same result with the FileMaker API for PHP would be extremely difficult and the performance would be much slower.

DDL

FileMaker 11 supports new options for some of the Data Definition Language (DDL) commands as well. For example, you can use the CREATE TABLE or ALTER TABLE commands to set some of the auto-enter options in FileMaker’s field options by using the DEFAULT keyword. Here’s an example that creates a new table named “log” with a text field named “account” and a date field named “creation_date”. The account field will have a field validation that limits the length to 30 characters and an auto-enter setting to insert the creation account name. The creation_date field will auto-enter the creation date for new records.

CREATE TABLE log (account VARCHAR (30) DEFAULT CURRENT_USER, creation_date DATE DEFAULT CURRENT_DATE)

The following examples show how to change some of the auto-enter options for existing fields:

ALTER TABLE log ALTER COLUMN account DROP DEFAULT
ALTER TABLE log ALTER COLUMN account SET DEFAULT CURRENT_USER

Other Changes

Other new features include the ability to access repeating fields with the familiar square-bracket syntax (i.e., myField[3] ), the ability to set the contents of container fields from an ODBC client application, and support for LEFT JOIN and RIGHT JOIN in the FROM clause.

Be Careful When You Upgrade

Along with all the improvements come a couple of things to be aware of as you consider upgrading your systems. Data in FileMaker 11 can not be accessed from previous versions of the FileMaker ODBC drivers, nor will the new FileMaker ODBC drivers access data shared by FileMaker 10 or earlier.

Also, FileMaker ODBC is now much more strict about data types. FileMaker scripts and calculations generally coerce data to the appropriate type and previous versions of FileMaker ODBC were similarly lenient regarding data type mismatches. Consider the following SQL statement:

INSERT INTO myTable (myTextField1, myTextField2) VALUES (10, DATE())

This worked fine in FileMaker 10 and earlier. In FileMaker 11, it will return an error:

[FileMaker][FileMaker ODBC] FQL0013/(1:40): Incompatible types in assignment.

The query must be changed to something like:

INSERT INTO myTable (myTextField1, myTextField2) VALUES (’10’, STRVAL(DATE()))

Conclusion

Overall, ODBC/SQL support in FileMaker 11 is much improved and the performance seems to be very good relative to previous versions. Improvements have also been made to JDBC, ESS, and the plug-in API that I’m sure will be leveraged in creative ways by many developers.

If you’d like to see what’s possible with all of the ODBC/JDBC/SQL/ESS features in FileMaker 11, consider attending this year’s FileMaker Developers Conference. There are at least seven different sessions and workshops that are focused on these features. I’ll be leading two of the sessions, a pre-conference session titled, “Introduction to ODBC, JDBC, and SQL for FileMaker Developers” and a session titled, “Getting Started with the New FileMaker ODBC and JDBC Integration”. I hope to see you there!

Recent Posts

C言語で配列に配列を代入するのは何故駄目なのか

C言語で配列に配列を代入すると、コンパイルエラーが発生します。例えば以下のコードをgccでコンパイルしようとすると、"incompatible types in assignment"というエラーが発生します。

1 /* header files */ 2 #include <stdlib.h> 3 #include <stdio.h> 4 5 /* main */ 6 int main (int argc, char *argv[]) { 7 char c1[] = "afa"; 8 char c2[4]; 9 10 c2 = c1; 11 12 return EXIT_SUCCESS; 13 }
|10| error: incompatible types in assignment

"incompatible types in assignment"とは、"互換性のない型に代入をしようとしている"という内容のエラーです。 char型の配列に、同じchar型の配列を代入しようしているのに互換性のない型だと怒られる。これは奇妙な話です。

何故駄目なのか

その理由を理解するためには、まず、C言語の右辺値と左辺値を知る必要があります。

右辺値と左辺値

例えば次のようなコードがあったとします。
int x = 100; x = x + 1;

初心に返って考えると、これはxという箱の中に入っている値を+1して、その結果をxという箱に格納するコードです。 つまり、左辺のx(左辺値)はxという箱を表し、右辺のxは100という値を表しているわけです。 これを一般化してまとめると以下のようになります。

  • 左辺値: 変数の領域そのものを表す
  • 右辺値: 変数の中身表す

配列の格下げ規則

さて、本題の配列についてですが、配列の右辺値と左辺値は、普通の変数のそれとは少し異なります。 結論からいってしまえば、配列の左辺値は、配列の領域全体を意味し、 右辺値は、配列の先頭要素の置かれてる領域を意味します。 これを図で表すと以下のようになります。


配列は右辺値になると、配列から「配列の先頭要素の置かれてる領域」という意味に格下げになります。 これを配列の格下げ規則といいます。

配列に配列を代入するのは何故駄目なのか(結論)

配列の格下げ規則によって、配列の領域全体を表す変数に配列の先頭領域を格納しようとしてしまいます。 これによって、「互換性のない型に代入しようとしているよ」とコンパイラに怒られるというわけです。


ラベル:C言語

posted by Kojo Sugita at 19:19| Comment(0) | 何故駄目なのか? | |

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *