{"id":146,"date":"2011-10-12T11:13:22","date_gmt":"2011-10-12T16:13:22","guid":{"rendered":"http:\/\/thenoyes.com\/littlenoise\/?p=146"},"modified":"2011-10-12T11:13:22","modified_gmt":"2011-10-12T16:13:22","slug":"whichlineterminator","status":"publish","type":"post","link":"https:\/\/thenoyes.com\/littlenoise\/?p=146","title":{"rendered":"whichLineTerminator"},"content":{"rendered":"<p>A stored function to guess which line terminator (&#8216;\\r&#8217; or &#8216;\\r\\n&#8217;) to use with LOAD DATA INFILE<\/p>\n<pre>CREATE FUNCTION whichLineTerminator(fileName varchar(255))\r\nRETURNS varchar(20)\r\nNOT DETERMINISTIC\r\nBEGIN\r\n  DECLARE cr_count int;\r\n  DECLARE lf_Count int;\r\n  DECLARE f text;\r\n\r\n  SET f := LOAD_FILE(fileName);\r\n\r\n  IF f IS NULL THEN RETURN 'Cannot read file.'; END IF;\r\n\r\n  SET cr_count := CHARACTER_LENGTH(f) - CHARACTER_LENGTH(REPLACE(f, '\\r', ''));\r\n  SET lf_count := CHARACTER_LENGTH(f) - CHARACTER_LENGTH(REPLACE(f, '\\n', ''));\r\n\r\n  IF cr_count >= lf_count \r\n  THEN RETURN '\\\\r\\\\n';\r\n  ELSE RETURN '\\\\n';\r\n  END IF;\r\nEND<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>A stored function to guess which line terminator (&#8216;\\r&#8217; or &#8216;\\r\\n&#8217;) to use with LOAD DATA INFILE CREATE FUNCTION whichLineTerminator(fileName varchar(255)) RETURNS varchar(20) NOT DETERMINISTIC BEGIN DECLARE cr_count int; DECLARE lf_Count int; DECLARE f text; SET f := LOAD_FILE(fileName); IF f IS NULL THEN RETURN &#8216;Cannot read file.&#8217;; END IF; SET cr_count := CHARACTER_LENGTH(f) &#8211; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4],"tags":[],"class_list":["post-146","post","type-post","status-publish","format-standard","hentry","category-mysql"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2IBF1-2m","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/posts\/146","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=146"}],"version-history":[{"count":1,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/posts\/146\/revisions"}],"predecessor-version":[{"id":147,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/posts\/146\/revisions\/147"}],"wp:attachment":[{"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=146"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=146"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=146"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}