// nlatexdb Version 0.03
// Database Access in LaTeX
// Copyright (C) 2011 Robin Höns, Integranova GmbH
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
//
// For more information see the web page http://hoens.net/robin
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace nlatexdb
{
class SqlQuery
{
public SqlQuery(string querytext, string queryvars)
{
m_querytext = querytext;
string[] qvars = queryvars.Split(m_variablesplitter);
m_queryvars = new List();
foreach (string s in qvars)
{
Processer.Debug("Var: {0}", s);
m_queryvars.Add(new SqlQueryVar(s.Trim()));
}
}
public static void SetVariableSplitter(string var_splitter)
{
m_variablesplitter = var_splitter.ToCharArray();
}
private void ReplaceVariables(System.Data.Common.DbCommand comm,
System.Collections.Generic.Dictionary varvalues)
{
string querytext = m_querytext;
System.Collections.Generic.SortedDictionary> repls =
new SortedDictionary>();
foreach (KeyValuePair var in varvalues)
{
int startindex = 0;
while (startindex >= 0 && startindex < querytext.Length)
{
int varindex = querytext.IndexOf(var.Key, startindex);
if (varindex >= 0)
{
repls[varindex] = new KeyValuePair(var.Key, var.Value.getValueSql());
startindex = varindex + 1;
}
else
{
break;
}
}
}
int j = 1;
// Alle Variablenvorkommen sind nun sortiert im repl-Verzeichnis.
foreach (KeyValuePair replacement in repls.Values)
{
string parname = String.Format("@{0}", j);
querytext = querytext.Replace(replacement.Key, parname);
System.Data.Common.DbParameter par = comm.CreateParameter();
par.Value = replacement.Value;
par.ParameterName = parname;
comm.Parameters.Add(par);
j++;
}
comm.CommandText = querytext;
}
private List