Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ jobs:
fail-fast: false
matrix:
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
- "3.13"
- "3.14"

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -96,11 +96,11 @@ jobs:
- name: Build Python package
run: ./scripts/build-dist.sh

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
if: github.event_name == 'pull_request'
with:
name: dist
path: dist/irissqlcli-${{ steps.set-version.outputs.version }}-py3-none-any.whl
path: dist/irissqlcli-*-py3-none-any.whl

- name: Create Release
id: create-release
Expand All @@ -109,7 +109,7 @@ jobs:
with:
tag_name: v${{ steps.set-version.outputs.version }}
prerelease: ${{ github.event_name != 'release' }}
files: dist/irissqlcli-${{ steps.set-version.outputs.version }}-py3-none-any.whl
files: dist/irissqlcli-*-py3-none-any.whl

- name: Publish package
if: github.event_name != 'pull_request'
Expand All @@ -119,8 +119,13 @@ jobs:
password: ${{ secrets.PYPI_API_TOKEN }}

- name: Docker login
run: docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push Docker images
if: github.event_name != 'pull_request'
run: make push

- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion irissqlcli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.5.7"
__version__ = "0.6.0"
from . import main
from . import utils

Expand Down
8 changes: 5 additions & 3 deletions irissqlcli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from cli_helpers.tabular_output import TabularOutputFormatter
from cli_helpers.tabular_output.preprocessors import align_decimals, format_numbers
from cli_helpers.utils import strip_ansi
from intersystems_iris.dbapi._DBAPI import OperationalError, DatabaseError
import iris
from prompt_toolkit.completion import DynamicCompleter, ThreadedCompleter
from prompt_toolkit.document import Document
from prompt_toolkit.enums import DEFAULT_BUFFER, EditingMode
Expand Down Expand Up @@ -434,7 +434,7 @@ def execute_command(self, text, handle_closed_connection=True):
click.secho("cancelled query", err=True, fg="red")
except NotImplementedError:
click.secho("Not Yet Implemented.", fg="yellow")
except DatabaseError as e:
except iris.dbapi.DatabaseError as e:
logger.error("sql: %r, error: %r", text, e)
logger.error("traceback: %r", traceback.format_exc())
click.secho(str(e), err=True, fg="red")
Expand Down Expand Up @@ -911,8 +911,10 @@ def cli(
hostname, port, namespace, username, password, embedded = parse_uri(
uri, hostname, port, namespace, username
)
else:
embedded = True

namespace = namespace or namespace_opt or "USER"
namespace = namespace or namespace_opt or os.getenv("IRISNAMESPACE") or "USER"
username = username or username_opt
irissqlcli = IRISSqlCli(
prompt_passwd,
Expand Down
33 changes: 22 additions & 11 deletions irissqlcli/sqlexecute.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
import intersystems_iris.dbapi._DBAPI as dbapi
import iris
import sqlparse
import traceback

Expand Down Expand Up @@ -91,16 +91,27 @@ def connect(self):
conn_params["embedded"] = self.embedded
conn_params.update(self.extra_params)

conn = dbapi.connect(**conn_params)
if self.embedded:
conn = iris.dbapi.connect(mode="embedded", namespace=self.namespace)
else:
conn = iris.dbapi.connect(hostname=conn_params["hostname"], port=conn_params["port"], namespace=conn_params["namespace"], username=conn_params["username"], password=conn_params["password"])
self.conn = conn
self.conn.setAutoCommit(True)
if not self.embedded:
self.conn.setAutoCommit(True)
if self.embedded:
self.server_version = self.conn.iris.system.Version.GetVersion()
self.username = self.conn.iris.system.Process.UserName()
self.namespace = self.conn.iris.system.Process.NameSpace()
self.hostname = self.conn.iris.system.Util.InstallDirectory()
self.server_version = iris.system.Version.GetVersion()
self.username = iris.system.Process.UserName()
if self.namespace is None:
self.namespace = iris.system.Process.NameSpace()
self.hostname = iris.system.Util.InstallDirectory()
else:
self.server_version = self.conn._connection_info._server_version
try:
iris_conn = iris.connect(hostname=conn_params["hostname"], port=conn_params["port"], namespace=conn_params["namespace"], username=conn_params["username"], password=conn_params["password"])
iris.runtime.configure(native_connection=iris_conn)
version =iris.system.Version.GetVersion()
self.server_version = version
except Exception as e:
self.server_version = "unknown"

def run(
self,
Expand Down Expand Up @@ -140,7 +151,7 @@ def run(
try:
try:
cur = self.conn.cursor()
except dbapi.InterfaceError:
except iris.dbapi.InterfaceError:
cur = None
try:
_logger.debug("Trying a dbspecial command. sql: %r", sql)
Expand All @@ -149,7 +160,7 @@ def run(
except special.CommandNotFound:
yield self.execute_normal_sql(sql) + (sql, True, False)

except dbapi.OperationalError as e:
except iris.dbapi.OperationalError as e:
_logger.error("sql: %r, error: %r", sql, e)
_logger.error("traceback: %r", traceback.format_exc())

Expand All @@ -169,7 +180,7 @@ def execute_normal_sql(self, split_sql):
if cursor.description:
headers = [x[0] for x in cursor.description]
status = "{0} row{1} in set"
cursor = list(cursor)
cursor = cursor.fetchall()
rowcount = len(cursor)
else:
_logger.debug("No rows in result.")
Expand Down
2 changes: 1 addition & 1 deletion requirements-iris.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
https://github.com/intersystems-community/intersystems-irispython/releases/download/3.8.0/intersystems_iris-3.8.0-py3-none-any.whl
iris-embedded-python-wrapper>=0.6.0
14 changes: 0 additions & 14 deletions scripts/build-dist.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
#!/bin/bash

packages=("iris" "intersystems_iris" "irisnative")
for package in ${packages[@]};
do
rm -f ./$package
package_path=`python -c "import importlib.util; print(importlib.util.find_spec('${package}').submodule_search_locations[0])"`
ln -s $package_path ./$package
done

set -eo pipefail

PROJECT="$( cd "$(dirname "$0")/.." ; pwd -P )"
Expand All @@ -25,10 +17,4 @@ mkdir -p "$PROJECT"/dist
cd "$PROJECT"
$PYTHON_BIN setup.py sdist bdist_wheel

for package in ${packages[@]};
do
rm -f $package
done
rm -rf intersystems-irispython

set +x
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ def pytest_configure(config: Config):
if not container:
pytest.iris_hostname = os.getenv("IRIS_HOSTNAME", "localhost")
pytest.iris_port = int(os.getenv("IRIS_PORT", 1972))
pytest.iris_username = os.getenv("IRIS_USERNAME", "_SYSTEM")
pytest.iris_username = os.getenv("IRIS_USERNAME", "SuperUser")
pytest.iris_password = os.getenv("IRIS_PASSWORD", "SYS")
pytest.iris_namespace = os.getenv("IRIS_NAMESPACE", "USER")
pytest.url
pytest.dburi = f"iris://{pytest.iris_username}:{pytest.iris_password}@{pytest.iris_hostname}:{pytest.iris_port}/{pytest.iris_namespace}"
return

print("Starting IRIS container:", container)
Expand Down
3 changes: 3 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def test_execute_arg_with_csv(executor, runner):


@dbtest()
@pytest.mark.skip(reason="This test is for batch mode, which is not yet implemented.")
def test_batch_mode(executor, runner):
run(executor, """create table test(a text)""")
run(executor, """insert into test values('abc'), ('def'), ('ghi')""")
Expand All @@ -79,6 +80,7 @@ def test_batch_mode(executor, runner):


@dbtest()
@pytest.mark.skip(reason="This test is for batch mode, which is not yet implemented.")
def test_batch_mode_table(executor, runner):
run(executor, """create table test(a text)""")
run(executor, """insert into test values('abc'), ('def'), ('ghi')""")
Expand Down Expand Up @@ -107,6 +109,7 @@ def test_batch_mode_table(executor, runner):


@dbtest()
@pytest.mark.skip(reason="This test is for batch mode, which is not yet implemented.")
def test_batch_mode_csv(executor, runner):
run(executor, """create table test(a text, b text)""")
run(executor, """insert into test (a, b) values('abc', 'de\nf'), ('ghi', 'jkl')""")
Expand Down
6 changes: 3 additions & 3 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
import platform
import multiprocessing

import intersystems_iris.dbapi._DBAPI as dbapi
import iris
import pytest

from irissqlcli.main import special


def db_connection(embedded=False):
if embedded:
conn = dbapi.connect(embedded=True)
conn = iris.dbapi.connect(mode="embedded")
else:
conn = dbapi.connect(
conn = iris.dbapi.connect(
hostname=pytest.iris_hostname,
port=pytest.iris_port,
namespace=pytest.iris_namespace,
Expand Down
Loading