{"id":1363,"date":"2006-12-11T21:49:55","date_gmt":"2006-12-12T01:49:55","guid":{"rendered":"http:\/\/www.hoogervorst.ca\/arthur\/?p=1363"},"modified":"2006-12-11T21:51:52","modified_gmt":"2006-12-12T01:51:52","slug":"lack-an-odbcy","status":"publish","type":"post","link":"http:\/\/www.hoogervorst.ca\/arthur\/?p=1363","title":{"rendered":"Lack-an-ODBCy"},"content":{"rendered":"<p><span class=\"dropcap\">T<\/span>he silly thing of having out-of-date interface files + up-to-date SDK files is that nothing matches and that (generally) the next step is to &#8216;duke it out&#8217; with everything, except for the compiler. Here&#8217;s what I was fighting out:\n<\/p>\n<p>Using generic ODBC calls (ADO, actually) you can basically filter out the provider&#8217;s database types: in this case, I&#8217;m after specific <a href=\"http:\/\/www.postgresql.org\/docs\/8.2\/static\/datatype.html\">Postgres datatypes<\/a>, but the concept should be the same for any database\/ODBC source. The API says the following:\n<\/p>\n<pre>\r\nProvidertypes:\r\n\r\nrecordset = connection.OpenSchema (QueryType, Criteria, SchemaID);\r\n\r\nwhere QueryType = adsProviderTypes,\r\n        QueryType = DATA_TYPE\/BEST_MATCH (not applicable for Postgres)\r\n        SchemaType = empty\r\n<\/pre>\n<p>To find a field&#8217;s datatype, you issue the same method with querytype of adsSchemaColumns and pass on the tablename as SchemaID. That particular dataset will return an ADO datatype for each field in a table (fieldname &#8216;DATA_TYPE&#8217;). Here&#8217;s where the confusing part comes in: there&#8217;s only one ADO type defined for string fields, namely DBTYPE_WSTR (well, not completely true, if your database doesn&#8217;t support Unicode, but I&#8217;ll leave that out for now). How to distinguish, say char(xx) and varchar(xx) fields? Or even, memo\/text types?\n<\/p>\n<p>The easy part is to tell the difference between, memo and varchar(xx) fields: varchar fields will generally have a maximum size (in case of Postgres, 254 characters). Memo&#8217;s generally don&#8217;t. So, to tell the difference between the two, do a crossreference on &#8216;CHARACTER_OCTET_LENGTH&#8217; (remember octets!) and &#8216;COLUMN_SIZE&#8217;. For the specific char vs. varchar issue, you apparently have to see if bit 16 (DBCOLUMNFLAGS_ISFIXEDLENGTH) is set in the adsSchemaColumns dataset&#8217;s &#8216;COLUMN_FLAGS&#8217;.<\/p>\n<p>Yes. Really. I&#8217;m not kidding.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The silly thing of having out-of-date interface files + up-to-date SDK files is that nothing matches and that (generally) the next step is to &#8216;duke it out&#8217; with everything, except for the compiler. Here&#8217;s what I was fighting out: Using &hellip; <a href=\"http:\/\/www.hoogervorst.ca\/arthur\/?p=1363\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[],"_links":{"self":[{"href":"http:\/\/www.hoogervorst.ca\/arthur\/index.php?rest_route=\/wp\/v2\/posts\/1363"}],"collection":[{"href":"http:\/\/www.hoogervorst.ca\/arthur\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.hoogervorst.ca\/arthur\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.hoogervorst.ca\/arthur\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.hoogervorst.ca\/arthur\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1363"}],"version-history":[{"count":0,"href":"http:\/\/www.hoogervorst.ca\/arthur\/index.php?rest_route=\/wp\/v2\/posts\/1363\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.hoogervorst.ca\/arthur\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1363"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.hoogervorst.ca\/arthur\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1363"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.hoogervorst.ca\/arthur\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1363"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}