@@ -40,53 +40,29 @@ if [ ! -f "$ODBC_64BIT" ]; then
4040 exit 1
4141fi
4242
43- case " $( uname) " in
44- Linux)
45- SYSTEM_ODBCINST_FILE=" /etc/odbcinst.ini"
46- ;;
47- * )
48- # macOS
49- SYSTEM_ODBCINST_FILE=" /Library/ODBC/odbcinst.ini"
50- mkdir -p /Library/ODBC
51- ;;
52- esac
43+ if ! command -v odbcinst > /dev/null 2>&1 ; then
44+ echo " error: odbcinst not found. Please install unixODBC first."
45+ exit 1
46+ fi
47+
48+ # On macOS, iODBC reads from /Library/ODBC/odbcinst.ini. Point odbcinst there
49+ # so the registration is visible to iODBC rather than written to the unixODBC
50+ # Homebrew path that iODBC never reads.
51+ if [ " $( uname) " = " Darwin" ]; then
52+ mkdir -p /Library/ODBC
53+ export ODBCINSTINI=/Library/ODBC/odbcinst.ini
54+ fi
5355
5456DRIVER_NAME=" Apache Arrow Flight SQL ODBC Driver"
5557
56- touch " $SYSTEM_ODBCINST_FILE "
58+ TEMPLATE_FILE=$( mktemp /tmp/arrow_odbc_XXXXXX.ini)
59+ trap ' rm -f "$TEMPLATE_FILE"' EXIT
5760
58- if grep -q " ^\[$DRIVER_NAME \]" " $SYSTEM_ODBCINST_FILE " ; then
59- echo " Driver [$DRIVER_NAME ] already exists in odbcinst.ini"
60- else
61- echo " Adding [$DRIVER_NAME ] to odbcinst.ini..."
62- echo "
61+ cat > " $TEMPLATE_FILE " << EOF
6362[$DRIVER_NAME ]
6463Description=An ODBC Driver for Apache Arrow Flight SQL
6564Driver=$ODBC_64BIT
66- " >> " $SYSTEM_ODBCINST_FILE "
67- fi
68-
69- # Check if [ODBC Drivers] section exists
70- if grep -q ' ^\[ODBC Drivers\]' " $SYSTEM_ODBCINST_FILE " ; then
71- # Section exists: check if driver entry exists
72- if ! grep -q " ^${DRIVER_NAME} =" " $SYSTEM_ODBCINST_FILE " ; then
73- # Driver entry does not exist, add under [ODBC Drivers]
65+ EOF
7466
75- awk -v driver=" $DRIVER_NAME " '
76- $0 ~ /^\[ODBC Drivers\]/ && !inserted {
77- print
78- print driver "=Installed"
79- inserted=1
80- next
81- }
82- { print }
83- ' " $SYSTEM_ODBCINST_FILE " > " ${SYSTEM_ODBCINST_FILE} .tmp" && mv " ${SYSTEM_ODBCINST_FILE} .tmp" " $SYSTEM_ODBCINST_FILE "
84- fi
85- else
86- # Section doesn't exist, append both section and driver entry at end
87- {
88- echo " "
89- echo " [ODBC Drivers]"
90- echo " ${DRIVER_NAME} =Installed"
91- } >> " $SYSTEM_ODBCINST_FILE "
92- fi
67+ echo " Registering [$DRIVER_NAME ] via odbcinst..."
68+ odbcinst -i -d -f " $TEMPLATE_FILE "
0 commit comments