Skip to content

Commit 929d388

Browse files
committed
Use odbcinst in install_odbc.sh
1 parent 2a9bb61 commit 929d388

2 files changed

Lines changed: 19 additions & 42 deletions

File tree

ci/docker/ubuntu-24.04-cpp.dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ RUN apt-get update -y -q && \
124124
sudo \
125125
tzdata \
126126
tzdata-legacy \
127+
unixodbc \
127128
unixodbc-dev \
128129
uuid-runtime \
129130
unzip \

cpp/src/arrow/flight/sql/odbc/install/unix/install_odbc.sh

Lines changed: 18 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -40,53 +40,29 @@ if [ ! -f "$ODBC_64BIT" ]; then
4040
exit 1
4141
fi
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

5456
DRIVER_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]
6463
Description=An ODBC Driver for Apache Arrow Flight SQL
6564
Driver=$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

Comments
 (0)