Skip to content

Commit 55939b1

Browse files
bpo-41074: Fix support of non-ASCII names and SQL in msilib. (GH-21126)
* Fix support of non-ASCII names in functions OpenDatabase() and init_database(). * Fix support of non-ASCII SQL in method Database.OpenView().
1 parent 152f0b8 commit 55939b1

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

Lib/test/test_msilib.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
""" Test suite for the code in msilib """
22
import os
33
import unittest
4-
from test.support import TESTFN, import_module, unlink
4+
from test.support import TESTFN, FS_NONASCII, import_module, unlink
55
msilib = import_module('msilib')
66
import msilib.schema
77

88

99
def init_database():
10-
path = TESTFN + '.msi'
10+
path = TESTFN + (FS_NONASCII or '') + '.msi'
1111
db = msilib.init_database(
1212
path,
1313
msilib.schema,
@@ -42,6 +42,16 @@ def test_view_fetch_returns_none(self):
4242
)
4343
self.addCleanup(unlink, db_path)
4444

45+
def test_view_non_ascii(self):
46+
db, db_path = init_database()
47+
view = db.OpenView("SELECT 'ß-розпад' FROM Property")
48+
view.Execute(None)
49+
record = view.Fetch()
50+
self.assertEqual(record.GetString(1), 'ß-розпад')
51+
view.Close()
52+
db.Close()
53+
self.addCleanup(unlink, db_path)
54+
4555
def test_summaryinfo_getproperty_issue1104(self):
4656
db, db_path = init_database()
4757
try:
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fixed support of non-ASCII names in functions :func:`msilib.OpenDatabase`
2+
and :func:`msilib.init_database` and non-ASCII SQL in method
3+
:meth:`msilib.Database.OpenView`.

PC/_msi.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -872,14 +872,14 @@ static PyObject*
872872
msidb_openview(msiobj *msidb, PyObject *args)
873873
{
874874
int status;
875-
char *sql;
875+
const wchar_t *sql;
876876
MSIHANDLE hView;
877877
msiobj *result;
878878

879-
if (!PyArg_ParseTuple(args, "s:OpenView", &sql))
879+
if (!PyArg_ParseTuple(args, "u:OpenView", &sql))
880880
return NULL;
881881

882-
if ((status = MsiDatabaseOpenView(msidb->h, sql, &hView)) != ERROR_SUCCESS)
882+
if ((status = MsiDatabaseOpenViewW(msidb->h, sql, &hView)) != ERROR_SUCCESS)
883883
return msierror(status);
884884

885885
result = PyObject_New(struct msiobj, &msiview_Type);
@@ -998,18 +998,18 @@ static PyTypeObject msidb_Type = {
998998
static PyObject* msiopendb(PyObject *obj, PyObject *args)
999999
{
10001000
int status;
1001-
char *path;
1001+
const wchar_t *path;
10021002
int persist;
10031003
MSIHANDLE h;
10041004
msiobj *result;
1005-
if (!PyArg_ParseTuple(args, "si:MSIOpenDatabase", &path, &persist))
1005+
if (!PyArg_ParseTuple(args, "ui:MSIOpenDatabase", &path, &persist))
10061006
return NULL;
10071007
/* We need to validate that persist is a valid MSIDBOPEN_* value. Otherwise,
10081008
MsiOpenDatabase may treat the value as a pointer, leading to unexpected
10091009
behavior. */
10101010
if (Py_INVALID_PERSIST(persist))
10111011
return msierror(ERROR_INVALID_PARAMETER);
1012-
status = MsiOpenDatabase(path, (LPCSTR)(SIZE_T)persist, &h);
1012+
status = MsiOpenDatabaseW(path, (LPCWSTR)(SIZE_T)persist, &h);
10131013
if (status != ERROR_SUCCESS)
10141014
return msierror(status);
10151015

0 commit comments

Comments
 (0)