Qt 4.8
Classes | Macros | Functions | Variables
qsql_symsql.cpp File Reference
#include "qsql_symsql.h"
#include <qcoreapplication.h>
#include <qvariant.h>
#include <qsqlerror.h>
#include <qsqlfield.h>
#include <qsqlindex.h>
#include <qsqlquery.h>
#include <qstringlist.h>
#include <qvector.h>
#include <qdebug.h>
#include "../../../corelib/kernel/qcore_symbian_p.h"
#include <qt_windows.h>
#include <sqldb.h>
#include <e32capability.h>

Go to the source code of this file.

Classes

class  QSymSQLDriverPrivate
 
class  QSymSQLResultPrivate
 

Macros

#define SYMBIAN_ENABLE_PUBLIC_PLATFORM_HEADER_SPLIT
 

Functions

static QString _q_escapeIdentifier (const QString &identifier)
 
static QSqlError gMakeErrorOpen (const QString &descr, QSqlError::ErrorType type, TInt errorCode)
 
bool qExtractSecurityPolicyFromString (const QString &string, TSecurityPolicy &policy)
 
static QVariant::Type qGetColumnType (const TSqlColumnType coltype)
 
static QVariant::Type qGetColumnType (const QString &tpName)
 
static QSqlError qMakeError (RSqlDatabase &access, const QString &descr, QSqlError::ErrorType type, int errorCode=-1)
 
TCapability qMatchCapStr (QString &str)
 Converts capability string to TCapability. More...
 

Variables

const QString fieldSeparator (QLatin1String(","))
 
const char * qCapabilityNames [ECapability_Limit]
 
const char qCapabilityNone [] = "None"
 
const QString valueSeparator (QLatin1String("="))
 

Macro Definition Documentation

◆ SYMBIAN_ENABLE_PUBLIC_PLATFORM_HEADER_SPLIT

#define SYMBIAN_ENABLE_PUBLIC_PLATFORM_HEADER_SPLIT

Definition at line 45 of file qsql_symsql.cpp.

Function Documentation

◆ _q_escapeIdentifier()

static QString _q_escapeIdentifier ( const QString identifier)
static

Definition at line 102 of file qsql_symsql.cpp.

Referenced by qExtractSecurityPolicyFromString().

103 {
104  QString res = identifier;
105  if (!identifier.isEmpty()
106  && identifier.left(1) != QString(QLatin1Char('"'))
107  && identifier.right(1) != QString(QLatin1Char('"'))) {
108  res.replace(QLatin1Char('"'), QLatin1String("\"\""));
109  res.prepend(QLatin1Char('"')).append(QLatin1Char('"'));
110  res.replace(QLatin1Char('.'), QLatin1String("\".\""));
111  }
112  return res;
113 }
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
QString & prepend(QChar c)
Definition: qstring.h:261
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QString right(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n rightmost characters of the string.
Definition: qstring.cpp:3682
QString & append(QChar c)
Definition: qstring.cpp:1777
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ gMakeErrorOpen()

static QSqlError gMakeErrorOpen ( const QString descr,
QSqlError::ErrorType  type,
TInt  errorCode 
)
static

Definition at line 161 of file qsql_symsql.cpp.

Referenced by qExtractSecurityPolicyFromString().

164 {
165  return QSqlError(descr, QLatin1String(""), type, errorCode);
166 }
The QSqlError class provides SQL database error information.
Definition: qsqlerror.h:53
int type
Definition: qmetatype.cpp:239
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString

◆ qExtractSecurityPolicyFromString()

bool qExtractSecurityPolicyFromString ( const QString string,
TSecurityPolicy &  policy 
)

Definition at line 696 of file qsql_symsql.cpp.

697 {
698  int startPos = string.indexOf(QLatin1Char('='));
700  bool ret = false;
701 
702  if (startPos == -1) {
703  values = string.split(QLatin1Char(','), QString::SkipEmptyParts);
704  } else {
705  values = string.mid(startPos + 1).split(QLatin1Char(','), QString::SkipEmptyParts);
706  }
707 
708  if (values.count() > 0) {
709  const QString findVid(QLatin1String("vid["));
710  const QString findSid(QLatin1String("sid["));
711  const int MaxCapCount = 7;
712  const int VidMaxCount = 3;
713  const int SidMaxCount = 3;
714 
715  TCapability capList[MaxCapCount] = { ECapability_None,ECapability_None,ECapability_None,
716  ECapability_None,ECapability_None,ECapability_None,ECapability_None };
717 
718  bool isVID = false;
719  bool isSID = false;
720 
721  QString idString(QLatin1String(""));
722  int maxAllowed = MaxCapCount;
723 
724  if (values[0].contains(findVid, Qt::CaseInsensitive)) {
725  idString = values[0].remove(findVid, Qt::CaseInsensitive);
726  idString = idString.remove(QLatin1Char(']'));
727  values.removeAt(0);
728  isVID = true;
729  maxAllowed = VidMaxCount;
730 
731  } else if (values[0].contains(findSid, Qt::CaseInsensitive)) {
732  idString = values[0].remove(findSid, Qt::CaseInsensitive);
733  idString = idString.remove(QLatin1Char(']'));
734  values.removeAt(0);
735  isSID = true;
736  maxAllowed = SidMaxCount;
737  }
738 
739  if (values.count() <= maxAllowed) {
740  bool wasSuccesful = true;
741 
742  for (int i = 0; i < values.count(); i++) {
743  capList[i] = qMatchCapStr(values[i]);
744 
745  if (capList[i] == ECapability_HardLimit) {
746  wasSuccesful = false;
747  break;
748  }
749  }
750 
751  if (wasSuccesful) {
752  if (isVID || isSID){
753  bool ok = true;
754  quint32 id = idString.toUInt(&ok, 16);
755 
756  if (ok) {
757  if (isVID) {
758  TVendorId vid(id);
759  policy = TSecurityPolicy(vid, capList[0], capList[1], capList[2]);
760  } else {
761  TSecureId sid(id);
762  policy = TSecurityPolicy(sid, capList[0], capList[1], capList[2]);
763  }
764 
765  ret = true; //Everything is fine
766  }
767  } else {
768  policy = TSecurityPolicy(capList[0], capList[1], capList[2], capList[3],
769  capList[4], capList[5], capList[6]);
770 
771  ret = true; //Everything is fine
772  }
773  }
774  }
775  }
776 
777  return ret;
778 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QString class provides a Unicode character string.
Definition: qstring.h:83
QList< T > mid(int pos, int length=-1) const
Returns a list whose elements are copied from this list, starting at position pos.
Definition: qlist.h:637
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
quint16 values[128]
TCapability qMatchCapStr(QString &str)
Converts capability string to TCapability.
unsigned int quint32
Definition: qglobal.h:938
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
void removeAt(int i)
Removes the item at index position i.
Definition: qlist.h:480

◆ qGetColumnType() [1/2]

static QVariant::Type qGetColumnType ( const TSqlColumnType  coltype)
static

Definition at line 115 of file qsql_symsql.cpp.

Referenced by QSymSQLResultPrivate::initColumns(), and qExtractSecurityPolicyFromString().

116 {
117  switch(coltype){
118  case ESqlInt:
119  case ESqlInt64:
120  return QVariant::Int;
121  case ESqlReal:
122  return QVariant::Double;
123  case ESqlBinary:
124  return QVariant::ByteArray;
125  case ESqlText:
126  case ESqlNull:
127  default:
128  return QVariant::String;
129  }
130 }

◆ qGetColumnType() [2/2]

static QVariant::Type qGetColumnType ( const QString tpName)
static

Definition at line 132 of file qsql_symsql.cpp.

133 {
134  const QString typeName = tpName.toLower();
135 
136  if (typeName == QLatin1String("integer")
137  || typeName == QLatin1String("int"))
138  return QVariant::Int;
139  if (typeName == QLatin1String("double")
140  || typeName == QLatin1String("float")
141  || typeName == QLatin1String("real")
142  || typeName.startsWith(QLatin1String("numeric")))
143  return QVariant::Double;
144  if (typeName == QLatin1String("blob"))
145  return QVariant::ByteArray;
146  return QVariant::String;
147 }
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
const char * typeName
Definition: qmetatype.cpp:239
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389

◆ qMakeError()

static QSqlError qMakeError ( RSqlDatabase &  access,
const QString descr,
QSqlError::ErrorType  type,
int  errorCode = -1 
)
static

Definition at line 149 of file qsql_symsql.cpp.

Referenced by QSymSQLResult::exec(), QSymSQLResultPrivate::fetchNext(), QSymSQLResultPrivate::initColumns(), and QSymSQLResult::prepare().

153 {
154  return QSqlError(descr,
155  QString::fromUtf16(static_cast<const ushort *>(access.LastErrorMessage().Ptr())),
156  type,
157  errorCode);
158 }
The QSqlError class provides SQL database error information.
Definition: qsqlerror.h:53
int type
Definition: qmetatype.cpp:239
int access(const char *, int)
static QString fromUtf16(const ushort *, int size=-1)
Returns a QString initialized with the first size characters of the Unicode string unicode (ISO-10646...
Definition: qstring.cpp:4329

◆ qMatchCapStr()

TCapability qMatchCapStr ( QString str)

Converts capability string to TCapability.

Definition at line 677 of file qsql_symsql.cpp.

Referenced by qExtractSecurityPolicyFromString().

678 {
679  TCapability cap = ECapability_HardLimit;
680 
681  for (int i = 0; i < static_cast<int>(ECapability_Limit); i++) {
683  cap = static_cast<TCapability>(i);
684  break;
685  }
686  }
687 
688  //Special case, we allow ECapability_None to be defined
689  if (cap == ECapability_HardLimit
691  cap = ECapability_None;
692 
693  return cap;
694 }
const char qCapabilityNone[]
Definition: qsql_symsql.cpp:91
const char * qCapabilityNames[ECapability_Limit]
Definition: qsql_symsql.cpp:67
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
int compare(const QString &s) const
Definition: qstring.cpp:5037

Variable Documentation

◆ fieldSeparator

const QString fieldSeparator(QLatin1String(","))

◆ qCapabilityNames

const char* qCapabilityNames[ECapability_Limit]
Initial value:
=
{
"TCB",
"CommDD",
"PowerMgmt",
"MultimediaDD",
"ReadDeviceData",
"WriteDeviceData",
"DRM",
"TrustedUI",
"ProtServ",
"DiskAdmin",
"NetworkControl",
"AllFiles",
"SwEvent",
"NetworkServices",
"LocalServices",
"ReadUserData",
"WriteUserData",
"Location",
"SurroundingsDD",
"UserEnvironment"
}

Definition at line 67 of file qsql_symsql.cpp.

Referenced by qMatchCapStr().

◆ qCapabilityNone

const char qCapabilityNone[] = "None"

Definition at line 91 of file qsql_symsql.cpp.

Referenced by qMatchCapStr().

◆ valueSeparator

const QString valueSeparator(QLatin1String("="))