MCPcopy Create free account
hub / github.com/MariaDB/server / Convert

Method Convert

storage/connect/array.cpp:564–628  ·  view source on GitHub ↗

/ Convert an array to new numeric type k. */ Note: conversion is always made in ascending order from STRING to */ short to int to double so no precision is lost in the conversion. */ One exception is converting from int to short compatible arrays. */ /

Source from the content-addressed store, hash-verified

562/* One exception is converting from int to short compatible arrays. */
563/***********************************************************************/
564int ARRAY::Convert(PGLOBAL g, int k, PVAL vp)
565 {
566 int i, prec = 0;
567 bool b = false;
568 PMBV ovblk = Valblk;
569 PVBLK ovblp = Vblp;
570
571 Type = k; // k is the new type
572 Valblk = new(g) MBVALS;
573
574 switch (Type) {
575 case TYPE_DOUBLE:
576 prec = 2;
577 /* fall through */
578 case TYPE_SHORT:
579 case TYPE_INT:
580 case TYPE_DATE:
581 Len = 1;
582 break;
583 default:
584 snprintf(g->Message, sizeof(g->Message), MSG(BAD_CONV_TYPE), Type);
585 return TYPE_ERROR;
586 } // endswitch k
587
588 Size = Nval;
589 Nval = 0;
590 Vblp = Valblk->Allocate(g, Type, Len, prec, Size);
591
592 if (!Valblk->GetMemp())
593 // The error message was built by PlgDBalloc
594 return TYPE_ERROR;
595 else
596 Value = AllocateValue(g, Type, Len, prec);
597
598 /*********************************************************************/
599 /* Converting STRING to DATE can be done according to date format. */
600 /*********************************************************************/
601 if (Type == TYPE_DATE && ovblp->GetType() == TYPE_STRING && vp)
602 {
603 if (((DTVAL*)Value)->SetFormat(g, vp))
604 return TYPE_ERROR;
605 else
606 b = true; // Sort the new array on date internal values
607 }
608
609 /*********************************************************************/
610 /* Do the actual conversion. */
611 /*********************************************************************/
612 for (i = 0; i < Size; i++) {
613 Value->SetValue_pvblk(ovblp, i);
614
615 if (AddValue(g, Value))
616 return TYPE_ERROR;
617
618 } // endfor i
619
620 /*********************************************************************/
621 /* For sorted arrays, get the initial find values. */

Callers

nothing calls this directly

Calls 7

AllocateValueFunction · 0.85
AllocateMethod · 0.80
GetMempMethod · 0.80
SetValue_pvblkMethod · 0.80
FreeMethod · 0.80
GetTypeMethod · 0.45
SetFormatMethod · 0.45

Tested by

no test coverage detected