Пример #1
0
//
// Helper function to create an ItemExpr tree that converts a SQL
// value to a SQL string without null terminator.
//
static ItemExpr *CreateLmString(ItemExpr &source,
                                const NAType &sourceType,
                                ComRoutineLanguage language,
                                ComRoutineParamStyle style,
                                CmpContext *cmpContext)
{
  //
  // We want an ItemExpr that converts any value X to a 
  // string. We will use this SQL syntax:
  //
  //   cast(X as {CHAR|VARCHAR}(N) CHARACTER SET ISO88591)
  //
  // where N is the max display length of X. The datatype of the
  // result will be CHAR(N) or VARCHAR(N) depending on the language.
  //
  ItemExpr *result = NULL;
  NAMemory *h = cmpContext->statementHeap();
  
  Lng32 maxLength = GetDisplayLength(sourceType);
  char buf[100];
  sprintf(buf, "%d", maxLength);

  NAString *s = new (h) NAString("cast (@A1 as ", h);
  if (style == COM_STYLE_JAVA_CALL)
    (*s) += "VARCHAR(";
  else
    (*s) += "CHAR(";
  (*s) += buf;
  (*s) += ") CHARACTER SET ISO88591);";
  
  result = ParseExpr(*s, *cmpContext, source);

  return result;
}
int CreateAllCharsExpr(const NAType &formalType,
                               ItemExpr &actualValue,
                               CmpContext *cmpContext,
                               ItemExpr *&newExpr)
{
  int result = 0;
  NAMemory *h = cmpContext->statementHeap();
  NAType *typ = NULL;

  Lng32 maxLength = GetDisplayLength(formalType);
  maxLength = MAXOF(maxLength, 1);

  if (formalType.getTypeQualifier() != NA_CHARACTER_TYPE )
  {
    typ = new (h) SQLVarChar(maxLength);
  }
  else
  {
    const CharType &cFormalType = (CharType&)formalType;
    typ = new (h) SQLVarChar( maxLength,
                              cFormalType.supportsSQLnull(),
                              cFormalType.isUpshifted(),
                              cFormalType.isCaseinsensitive(),
                              cFormalType.getCharSet(),
                              cFormalType.getCollation(),
                              cFormalType.getCoercibility(),
                              cFormalType.getEncodingCharSet());
  }

  newExpr = CreateCastExpr(actualValue, *typ, cmpContext);


  if (newExpr == NULL)
  {
    result = -1;
  }

  return result;
}
Пример #3
0
void VideoMetadata::toMap(MetadataMap &metadataMap)
{
    if (this == NULL)
        return;

    QString coverfile;
    if (IsHostSet()
        && !GetCoverFile().startsWith("/")
        && !GetCoverFile().isEmpty()
        && !IsDefaultCoverFile(GetCoverFile()))
    {
        coverfile = generate_file_url("Coverart", GetHost(),
                GetCoverFile());
    }
    else
    {
        coverfile = GetCoverFile();
    }

    metadataMap["coverfile"] = coverfile;

    QString screenshotfile;
    if (IsHostSet() && !GetScreenshot().startsWith("/")
        && !GetScreenshot().isEmpty())
    {
        screenshotfile = generate_file_url("Screenshots",
                GetHost(), GetScreenshot());
    }
    else
    {
        screenshotfile = GetScreenshot();
    }

    metadataMap["screenshotfile"] = screenshotfile;

    QString bannerfile;
    if (IsHostSet() && !GetBanner().startsWith("/")
        && !GetBanner().isEmpty())
    {
        bannerfile = generate_file_url("Banners", GetHost(),
                GetBanner());
    }
    else
    {
        bannerfile = GetBanner();
    }

    metadataMap["bannerfile"] = bannerfile;

    QString fanartfile;
    if (IsHostSet() && !GetFanart().startsWith("/")
        && !GetFanart().isEmpty())
    {
        fanartfile = generate_file_url("Fanart", GetHost(),
                GetFanart());
    }
    else
    {
        fanartfile = GetFanart();
    }

    metadataMap["fanartfile"] = fanartfile;

    metadataMap["filename"] = GetFilename();
    metadataMap["title"] = GetTitle();
    metadataMap["subtitle"] = GetSubtitle();
    metadataMap["tagline"] = GetTagline();
    metadataMap["director"] = GetDirector();
    metadataMap["studio"] = GetStudio();
    metadataMap["description"] = GetPlot();
    metadataMap["genres"] = GetDisplayGenres(*this);
    metadataMap["countries"] = GetDisplayCountries(*this);
    metadataMap["cast"] = GetDisplayCast(*this).join(", ");
    metadataMap["rating"] = GetDisplayRating(GetRating());
    metadataMap["length"] = GetDisplayLength(GetLength());
    metadataMap["year"] = GetDisplayYear(GetYear());

    metadataMap["releasedate"] = MythDateToString(GetReleaseDate(), kDateFull);

    metadataMap["userrating"] = GetDisplayUserRating(GetUserRating());
    metadataMap["season"] = GetDisplaySeasonEpisode(GetSeason(), 1);
    metadataMap["episode"] = GetDisplaySeasonEpisode(GetEpisode(), 1);

    if (GetSeason() > 0 || GetEpisode() > 0)
    {
        metadataMap["s##e##"] = QString("s%1e%2").arg(GetDisplaySeasonEpisode
                                             (GetSeason(), 2))
                        .arg(GetDisplaySeasonEpisode(GetEpisode(), 2));
        metadataMap["##x##"] = QString("%1x%2").arg(GetDisplaySeasonEpisode
                                             (GetSeason(), 1))
                        .arg(GetDisplaySeasonEpisode(GetEpisode(), 2));
    }
    else
        metadataMap["s##e##"] = metadataMap["##x##"] = QString();

    metadataMap["trailerstate"] = TrailerToState(GetTrailer());
    metadataMap["userratingstate"] =
            QString::number((int)(GetUserRating()));
    metadataMap["watchedstate"] = WatchedToState(GetWatched());

    metadataMap["videolevel"] = ParentalLevelToState(GetShowLevel());

    metadataMap["insertdate"] = MythDateToString(GetInsertdate(), kDateFull);
    metadataMap["inetref"] = GetInetRef();
    metadataMap["homepage"] = GetHomepage();
    metadataMap["child_id"] = QString::number(GetChildID());
    metadataMap["browseable"] = GetDisplayBrowse(GetBrowse());
    metadataMap["watched"] = GetDisplayWatched(GetWatched());
    metadataMap["processed"] = GetDisplayProcessed(GetProcessed());
    metadataMap["category"] = GetCategory();
}
Пример #4
0
//---------------------------------------------------------------------------
// CreateLmOutputExpr
// 
// Creates an ItemExpr tree to convert a value in LM-normal form to 
// SQL native format. Returns the tree in outputValue. The expressions
// will be used by a UDR TCB to process a UDR output value in the UDR
// server's reply buffer.
// 
// One other side-effect of this function:
// This function determines the SQL type that corresponds to LM-normal
// form and creates an NATypeToItem instance of that type. This NATypeToItem
// represents a UDR output value that has just come back from the UDR server
// in a reply buffer. A UDR TCB must convert the value from LM-normal format
// to the SQL formal parameter type. To allow codegen for the UDR TCB to set
// up the map table correctly, we return the NATypeToItem instance in 
// normalizedValue.
//---------------------------------------------------------------------------
LmExprResult CreateLmOutputExpr(const NAType &formalType,
                                ComRoutineLanguage language,
                                ComRoutineParamStyle style,
                                CmpContext *cmpContext,
                                ItemExpr *&normalizedValue,
                                ItemExpr *&outputValue,
                                NABoolean isResultSet)
{
  LmExprResult result = LmExprError;
  normalizedValue = NULL;
  outputValue = NULL;
  NAMemory *h = cmpContext->statementHeap();
  NAType *replyType = NULL;
  NABoolean isString = LmTypeIsString(formalType, language, style, isResultSet);

  if (isString &&
      (formalType.getTypeQualifier() != NA_CHARACTER_TYPE))
  {
    if (isResultSet || style != COM_STYLE_JAVA_CALL)
    {
      Lng32 maxLength = GetDisplayLength(formalType);
      replyType = new (h) SQLChar(maxLength);
    }
    else
    {
      Lng32 maxLength = GetDisplayLength(formalType);
      replyType = new (h) SQLVarChar(maxLength);
    }
  }
  else
  {
    replyType = formalType.newCopy(h);
  }
  
  if (replyType)
  {
    if (style == COM_STYLE_JAVA_CALL)
    {
      // $$$$ TBD: let's assume all CALL statement parameters are
      // nullable for now, until we are sure UDR server's null
      // processing is correct for both nullable and non-nullable
      // types.
      replyType->setNullable(TRUE);
    }
    else
      // Copy the nullability attribute from the formal type
      replyType->setNullable(formalType);

    normalizedValue = new (h) NATypeToItem(replyType->newCopy(h));
    if (normalizedValue)
    {
      // Note that we didn't apply cast expr for CHAR and VARCHAR for
      // IN params. But we need to have cast expr for OUT params, even
      // though there is no actual casting of data, because we need to
      // move data from buffer to up Queue in the root node.

      if (formalType.getTypeQualifier() == NA_INTERVAL_TYPE && isString)
        outputValue = CreateIntervalExpr(*normalizedValue,
                                         formalType,
                                         cmpContext);
      else
      {
    	// Fix for bug 3137.
    	// Set the parser flag to allow VARCHAR(0) as proxy column type
    	// before entering the parser. See comment above for more detail.
    	if (isResultSet && formalType.getTypeQualifier() == NA_CHARACTER_TYPE)
    	   inRSProxyStmt = TRUE;
        outputValue = CreateCastExpr(*normalizedValue,
                                     formalType,
                                     cmpContext);
        inRSProxyStmt = FALSE;
      }

      if (outputValue)
      {
        result = LmExprOK;
      }
      else
      {
        normalizedValue = NULL;
      }
    }
  }
  
  return result;
}