I cant insert my values into my SQLite table - android-studio

So I have been working roughly all the Christmas with this, but it seems like I cant actually find a way, I just create this account because of it. So, lets go into the code.
In first stance, I wanna warning the variables and all that are in spanish, but I dont think it will be a problem.
I have been taking a lot of data, its... if I recall correctly 53 or 56 columns in my SQL table or something like. I have been recollecting data through all the app and getting it through each activity by "putExtra". This is for a project for my school, so I have to use SQLite (I would like to use firebase, being honest) so, whatever, lets go into the code, which is the important stuff.
#Override
public void onCreate(SQLiteDatabase BaseDeDatos) {
//Creamos instancia a nuestra clase de BD
BaseDeDatos.execSQL("create table datos_personaje (apellido text primary key, nombre text, edad int, genero text, raza text, clase text, " +
"fuerza int, destreza int, resistencia int, inteligencia int, percepcion int, voluntad int, carisma int, apariencia int, manipulacion int, " +
"pelea int, atletismo int, robar int, sigilo int, nadar int, montar int, abrirCerr int, resDolorF int, escalar int, evadir int, esquivar int, bloquear int, " +
"alerta int, supervivencia int, coherencia int, rastrear int, concentracion int, buscar int, esconderse int, resDolorM int, estrategia int, escuchar int, conGeneral int, tasar int, " +
"mentir int, empatia int, liderazgo int, intimidar int, callejeo int, comercio int, seducir int, protocolo int, convencer int, actuar int, timar int, disfraz int, " +
"tecnicasHechizos text, inventario text)");
}
This is the creation of the table, I would say its alright.
public void SQLiteAyuda() {
Bundle extras = getIntent().getExtras();
String nombre = extras.getString("nombre");
String apellidos = extras.getString("apellidos");
int edad = extras.getInt("edad");
String genero = extras.getString("genero");
String raza = extras.getString("raza");
String clase = extras.getString("clase");
int f = extras.getInt("principalesF");
int d = extras.getInt("principalesD");
int r = extras.getInt("principalesR");
int i = extras.getInt("principalesI");
int p = extras.getInt("principalesP");
int v = extras.getInt("principalesV");
int c = extras.getInt("principalesC");
int a = extras.getInt("principalesA");
int m = extras.getInt("principalesM");
int pelea = extras.getInt("pelea");
int atletismo = extras.getInt("atletismo");
int robar = extras.getInt("robar");
int sigilo = extras.getInt("sigilo");
int nadar = extras.getInt("nadar");
int montar = extras.getInt("montar");
int abrirCerr = extras.getInt("abrircerr");
int resDolorF = extras.getInt("resdolorf");
int escalar = extras.getInt("escalar");
int evadir = extras.getInt("evadir");
int bloquear = extras.getInt("bloquear");
int esquivar = extras.getInt("esquivar");
int alerta = extras.getInt("alerta");
int supervivencia = extras.getInt("supervivencia");
int coherencia = extras.getInt("coherencia");
int rastrear = extras.getInt("rastrear");
int concentracion = extras.getInt("concentracion");
int buscar = extras.getInt("buscar");
int esconderse = extras.getInt("esconderse");
int resDolorM = extras.getInt("resDolorM");
int estrategia = extras.getInt("estrategia");
int escuchar = extras.getInt("escuchar");
int conGeneral = extras.getInt("conGeneral");
int tasar = extras.getInt("tasar");
int mentir = extras.getInt("mentir");
int empatia = extras.getInt("empatia");
int liderazgo = extras.getInt("liderazgo");
int intimidar = extras.getInt("intimidar");
int callejeo = extras.getInt("callejeo");
int comercio = extras.getInt("comercio");
int seducir = extras.getInt("seducir");
int protocolo = extras.getInt("protocolo");
int convencer = extras.getInt("convencer");
int actuar = extras.getInt("actuar");
int timar = extras.getInt("conGeneral");
int disfraz = extras.getInt("disfraz");
String poderes = extras.getString("tecnicasHechizos");
String inventario = inventarioText.getText().toString();
I get all my data in the last activity, so I can get it into the SQL table:
AdminSQLiteOpenHelper admin = new AdminSQLiteOpenHelper(this, "datos_personaje", null, 2);
SQLiteDatabase BaseDeDatos = admin.getWritableDatabase();
ContentValues datos = new ContentValues();
datos.put("nombre", nombre);
datos.put("apellido", apellidos);
datos.put("edad", edad);
datos.put("genero", genero);
datos.put("raza", r);
datos.put("clase", c);
datos.put("fuerza", f);
datos.put("destreza", d);
datos.put("resistencia", r);
datos.put("inteligencia", i);
datos.put("percepcion", p);
datos.put("voluntad", v);
datos.put("carisma", c);
datos.put("apariencia", a);
datos.put("manipulacion", m);
datos.put("pelea", pelea);
datos.put("atletismo", atletismo);
datos.put("robar", robar);
datos.put("sigilo", sigilo);
datos.put("nadar", nadar);
datos.put("montar", montar);
datos.put("abrircerr", abrirCerr);
datos.put("resdolorf", resDolorF);
datos.put("escalar", escalar);
datos.put("evadir", evadir);
datos.put("esquivar", esquivar);
datos.put("bloquear", bloquear);
datos.put("alerta", alerta);
datos.put("supervivencia", supervivencia);
datos.put("coherencia", coherencia);
datos.put("rastrear", rastrear);
datos.put("concentracion", concentracion);
datos.put("buscar", buscar);
datos.put("esconderse", esconderse);
datos.put("resDolorM", resDolorM);
datos.put("estrategia", estrategia);
datos.put("escuchar", escuchar);
datos.put("conGeneral", conGeneral);
datos.put("tasar", tasar);
datos.put("mentir", mentir);
datos.put("empatia", empatia);
datos.put("liderazgo", liderazgo);
datos.put("intimidar", intimidar);
datos.put("callejeo", callejeo);
datos.put("comercio", comercio);
datos.put("seducir", seducir);
datos.put("protocolo", protocolo);
datos.put("convencer", convencer);
datos.put("actuar", actuar);
datos.put("timar", timar);
datos.put("disfraz", disfraz);
datos.put("tecnicasHechizos", poderes);
datos.put("inventario", inventario);
BaseDeDatos.insert("datos_personaje", null, datos);
BaseDeDatos.close();
And the debugger shows me the next output:
E/SQLiteLog: (1)
E/SQLiteDatabase: Error inserting table datos_personaje has no column named coherencia (Sqlite code 1): , while compiling: INSERT INTO datos_personaje(esconderse,sigilo,protocolo,resdolorf,carisma,genero,destreza,inventario,escalar,alerta,liderazgo,raza,rastrear,escuchar,inteligencia,pelea,edad,disfraz,abrircerr,buscar,manipulacion,comercio,evadir,nadar,actuar,resDolorM,bloquear,conGeneral,resistencia,coherencia,mentir,apariencia,estrategia,tasar,montar,esquivar,robar,nombre,fuerza,clase,supervivencia,atletismo,callejeo,apellido,intimidar,timar,tecnicasHechizos,concentracion,voluntad,percepcion,seducir,convencer,empatia) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?), (OS error - 2:No such file or directory)

Related

error C4700: uninitialized local variable; How to initialize it in MFC application

Here is the little part of my code, I'm trying to convert my string operants into integer when I need it with the atoi. And I am encountering an error "uninitialized local variable ". How could I fix this problem?
CDC * pDC = GetDC();
CSize cz;
input1.GetWindowTextW(operant1);
input2.GetWindowTextW(operant2);
combo.GetWindowTextW(advanced_text);
if(groupCheckRadio == 0){ //AND
const char* operant1;
const char* operant2;
int num1 = atoi(operant1);
int num2 = atoi(operant2);
result = (num1 & num2);
}
if(groupCheckRadio == 1){ //OR
const char* operant1;
const char* operant2;
int num1 = atoi(operant1);
int num2 = atoi(operant2);
result = (num1 | num2);
}
if(groupCheckRadio == 2){ //XOR
const char* operant1;
const char* operant2;
int num1 = atoi(operant1);
int num2 = atoi(operant2);
result = (num1 ^ num2);
}
//shifting bits
if(checkShift.GetCheck() == 1){
int selected_index = combo.GetCurSel();
combo.GetLBText(selected_index,advanced_text);
}
If anyone If anyone wants to convert Cstring to integer after that, they can solve it using _ttof
CString operant1,operant2,bit,advanced_text,result,num_bin;
double numd1,numd2,resultd,bind,numdbin;
input1.GetWindowTextW(operant1);
input2.GetWindowTextW(operant2);
combo.GetWindowTextW(advanced_text);
input_bit.GetWindowTextW(num_bin);
CDC * pDC = GetDC();
CSize cz;
cz = pDC->GetTextExtent(result);
resultd = _ttof(result);
numd1 = _ttof(operant1);
numd2 = _ttof(operant2);
unsigned int resulti = int (resultd);
unsigned int num1 = int (numd1);
unsigned int num2 = int (numd2);
''

Example search name by a specific number

Example
I would like to compare the SDK number with a value and display the name of the value example sdk 25 = nougat
String sdks = Build.VERSION.SDK;
int Alpha = 1;
int Beta = 2;
int CupCake = 3;
int Donut = 4;
int Eclair= 5-7;
int Froyo = 8;
int GingerBread = 9-10;
int HoneyComb = 11-13;
int IceCreamSandwich = 14-15;
int JellyBean = 16-18;
int KitKat = 19-20;
int Lollipop = 21-22;
int MarshMellow = 23;
int Nougat = 24-25;
int Oreo = 26-27;
int Pie = 28;
resultview.setText(sdks);
I think a Map solution would be simple to implement given its a small range
public static void main(String []args){
Map<Integer,String> sdkMap = new HashMap<Integer,String>();
//populate other fields similarly
HelloWorld.populateRange("24-25","Nougat",sdkMap);
System.out.println(sdkMap.get(24));
}
public static void populateRange(String range,String name, Map<Integer,String> sdkMap){
String[] splitNumbers = range.split("-");
int low = Integer.parseInt(splitNumbers[0]);
int high = Integer.parseInt(splitNumbers[1]);
for(int i=low;i<=high;i++){
sdkMap.put(i,name);
}
}
Working example

Calling Fortran package in C

I reference About using Fortran function in C with iso_c_binding to write a intermediate program so that Odrpack95 (http://www.netlib.org/odrpack/) can be called in C. But I encounter some problems and need someone help.
Fortran code
subroutine wrapper_ODR(FCN,N,M,NP,NQ,BETA,Y,X,&
DELTA,WE,WD,IFIXB,IFIXX,JOB,NDIGIT,TAUFAC,&
SSTOL,PARTOL,MAXIT,IPRINT,LUNERR,LUNRPT,&
STPB,STPD,SCLB,SCLD,WORK,IWORK,INFO,LOWER,UPPER) bind(C, name='wrapper_ODR')
!DEC$ ATTRIBUTES DLLEXPORT :: wrapper_ODR
use iso_c_binding
use ODRPACK95
implicit none
interface
subroutine FCN(N,M,NP,NQ,LDN,LDM,LDNP,BETA,XPLUSD,IFIXB,IFIXX,LDIFX,&
IDEVAL,F,FJACB,FJACD,ISTOP) bind(C)
use, intrinsic :: iso_c_binding
implicit none
integer(c_int) :: IDEVAL,ISTOP,LDIFX,LDM,LDN,LDNP,M,N,NP,NQ
real (c_double) :: BETA(1:NP),F(1:LDN,1:NQ),FJACB(1:LDN,1:LDNP,1:NQ), &
FJACD(1:LDN,1:LDM,1:NQ),XPLUSD(1:LDN,1:M)
integer(c_int) :: IFIXB(1:NP),IFIXX(1:LDIFX,1:M)
end subroutine
end interface
integer(c_int) :: N,M,NP,NQ
real(c_double) :: BETA(1:NP),Y(1:N,1:NQ),X(1:N,1:M)
!!!!!Optional
integer(c_int), optional :: IFIXB(:),IFIXX(:,:),JOB,NDIGIT,MAXIT&
,IPRINT,LUNERR,LUNRPT,IWORK(:),INFO
real(c_double), optional :: DELTA(:,:),&
WE(:,:,:),WD(:,:,:),TAUFAC,SSTOL,PARTOL,&
STPB(:),STPD(:,:),SCLB(:),SCLD(:,:),&
WORK(:),LOWER(:),UPPER(:)
call ODR(inter_func,N,M,NP,NQ,BETA,Y,X)
contains
subroutine inter_func(N,M,NP,NQ,LDN,LDM,LDNP,BETA,XPLUSD,IFIXB,IFIXX,LDIFX,&
IDEVAL,F,FJACB,FJACD,ISTOP)
use REAL_PRECISION
integer :: IDEVAL,ISTOP,LDIFX,LDM,LDN,LDNP,M,N,NP,NQ
REAL (KIND=R8) :: BETA(1:NP),F(1:LDN,1:NQ),FJACB(1:LDN,1:LDNP,1:NQ), &
FJACD(1:LDN,1:LDM,1:NQ),XPLUSD(1:LDN,1:M)
INTEGER :: IFIXB(1:NP),IFIXX(1:LDIFX,1:M)
integer(c_int) :: inter_IDEVAL,inter_ISTOP,inter_LDIFX,inter_LDM,&
inter_LDN,inter_LDNP,inter_M,inter_N,inter_NP,inter_NQ
real (c_double) :: inter_BETA(1:size(BETA)),inter_F(1:size(F,1),1:size(F,2)),&
inter_FJACB(1:size(FJACB,1),1:size(FJACB,3),1:size(FJACB,3)),&
inter_FJACD(1:size(FJACD,1),1:size(FJACD,2),1:size(FJACD,3)),inter_XPLUSD(1:size(XPLUSD,1),1:size(XPLUSD,2))
integer(c_int) :: inter_IFIXB(1:size(IFIXB)),inter_IFIXX(1:size(IFIXX,1),1:size(IFIXX,2))
inter_IDEVAL = IDEVAL
inter_ISTOP = ISTOP
inter_LDIFX = LDIFX
inter_LDM = LDM
inter_LDN = LDN
inter_LDNP = LDNP
inter_M = M
inter_N = N
inter_NP = NP
inter_NQ = NQ
!!!!REAL
inter_BETA = BETA
inter_F = F
inter_FJACB = FJACB
inter_FJACD = FJACD
inter_XPLUSD = XPLUSD
!!!!INTEGER[]
inter_IFIXB = IFIXB
inter_IFIXX = IFIXX
end subroutine inter_func
end subroutine wrapper_ODR
C code
(I translated and modified from simple_example.f90 inside ODRPACK95 )
#include "stdafx.h"
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
extern "C" {
void wrapper_ODR(void(*FCN)(int*, int*, int*, int*, int*, int*, int*, \
double [] ,double [1][4],int [], int [],int* ,\
int*, double [1][4],double [1][2][4],double [] ,int* ),\
int *N,int *M,int *NP,int *NQ,double BETA[],double Y[1][4],double X[1][4],\
double DELTA[1][4],double WE[],double WD[],int IFIXB[],int IFIXX[],\
int *JOB,int *NDIGIT,double *TAUFAC,double *SSTOL, double *PARTOL,\
int *MAXIT, int *IPRINT, int *LUNERR, int *LUNRPT,double STPB[],\
double STPD[], double SCLB[], double SCLD[], double WORK[], double IWORK[],\
int *INFO, double LOWER[], double UPPER[]);
}
void FCN(int *N, int *M, int *NP, int *NQ, int *LDN, int *LDM, int *LDNP,\
double BETA[], double XPLUSD[1][4], int IXIFB[], int IFIXX[],int *LDIFX,\
int *IDEVAL, double F[1][4], double FJACB[1][2][4], double FJACD[],int *ISTOP){
// BETA[NP], XPLUSD[M][LDN], IXIFB[NP], IFIXX[M][LDIFX], F[NQ][LDN], FJACB[NQ][LDNP][LDN], FJACD[NQ][LDM][LDN]
*ISTOP =5;
if (fmod(*IDEVAL,10.0)!=0) {
for (int i = 0; i < *N; i++) {
F[0][i] = BETA[0] * XPLUSD[0][i] + BETA[1];
}
}
}
int main(){
//X[M][N] Y[NQ][N],BETA[NP]
int NP = 2, N = 4, M = 1, NQ = 1;
double BETA[] = { 2.0, 0.5 };
double X[1][4] = { 0.0, 1.0, 2.0, 3.0 };
double Y[1][4] = { 2.0, 5.0, 8.0, 11.0 };
wrapper_ODR(&FCN, &N, &M, &NP, &NQ, BETA, Y, X, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, \
NULL, NULL, NULL, NULL, NULL, NULL, NULL,NULL, NULL, NULL, NULL, NULL, NULL, \
NULL, NULL);
system("pause");
return 0;
}
Where NP = 2, N = 4,M = 1, NQ = 1, LDN = 4, LDM = 1, LDNP = 2,LDIFX = 4
Problems
ISTOP is used for stopping regression procedure if ISTOP is not equal to 0. However when C code above is executed, no matter what ISTOP is, it continues regression procedure. It seems that ISTOP doesn't pass to subroutine inter_func.
In Fortran code, comment parts with ! denote as passing array data parts. Well it doesn't ring any bell how to pass array data from C to Fortran or Fortran to C by inter_ variable.
Updated
I modify C and Fortran code above, the result shown below:
In C code, I set ISTOP = 5, but the result report shows it is 0.
Then if ODRPACK procedure succeeds, it should be like this:
And here is also Fortran code modified from simple_example.f90, It should be the same with C code:
PROGRAM ODRPACK95_EXAMPLE
USE ODRPACK95
USE REAL_PRECISION
REAL (KIND=R8), ALLOCATABLE :: BETA(:),X(:,:),Y(:,:)
INTEGER :: NP,N,M,NQ
INTERFACE
SUBROUTINE FCN(N,M,NP,NQ,LDN,LDM,LDNP,BETA,XPLUSD,IFIXB,IFIXX,LDIFX,&
IDEVAL,F,FJACB,FJACD,ISTOP)
USE REAL_PRECISION
INTEGER :: IDEVAL,ISTOP,LDIFX,LDM,LDN,LDNP,M,N,NP,NQ
REAL (KIND=R8) :: BETA(NP),F(LDN,NQ),FJACB(LDN,LDNP,NQ), &
FJACD(LDN,LDM,NQ),XPLUSD(LDN,M)
INTEGER :: IFIXB(NP),IFIXX(LDIFX,M)
END SUBROUTINE FCN
END INTERFACE
NP = 2
N = 4
M = 1
NQ = 1
ALLOCATE(BETA(NP),X(N,M),Y(N,NQ))
BETA(1:2) = (/ 2.0_R8, 0.5_R8 /)
X(1:4,1) = (/ 0_R8, 1_R8, 2_R8, 3_R8 /)
Y(1:4,1) = (/ 2_R8, 5_R8, 8_R8, 11_R8 /)
CALL ODR(FCN,N,M,NP,NQ,BETA,Y,X)
pause
END PROGRAM ODRPACK95_EXAMPLE
SUBROUTINE FCN(N,M,NP,NQ,LDN,LDM,LDNP,BETA,XPLUSD,IFIXB,IFIXX,LDIFX,&
IDEVAL,F,FJACB,FJACD,ISTOP)
USE REAL_PRECISION
INTEGER :: IDEVAL,ISTOP,LDIFX,LDM,LDN,LDNP,M,N,NP,NQ, I
REAL (KIND=R8) :: BETA(NP),F(LDN,NQ),FJACB(LDN,LDNP,NQ), &
FJACD(LDN,LDM,NQ),XPLUSD(LDN,M)
INTEGER :: IFIXB(NP),IFIXX(LDIFX,M)
ISTOP = 0
!Calculate model.
IF (MOD(IDEVAL,10).NE.0) THEN
DO I=1,N
F(I,1) = BETA(1)*XPLUSD(I,1)+BETA(2)
END DO
END IF
END SUBROUTINE FCN
It seems that the variable value of C function FCN doesn't pass to wrapper_ODR, but I don't know where are my problems? Could someone help me?

Multiple ints to const char*

I'm trying to make as string out of multiple ints.
Let's say:
int year = 1995;
int month = 12;
int day = 18;
const char* date = ("%d-%d-%d", month, day, year);
I get:
error: invalid conversion from 'int' to 'const char*' [-fpermissive]
What's the best way to go about this?
First, convert your parameters to strings with std::to_string().
string m = std::to_string(month);
string d = std::to_string(day);
string y = std::to_string(year);
Then, concatenate them:
string datestr = m + d + y;
Finally, convert that string into a char const*, using c_str(), which converts a string int to a C-like string.
char const* date = date.c_str();

Retrieve integer value of enum

Given:
public enum myType
{
Val1 = 1,
Val2 = 2,
Val3 = 3
}
and code elsewhere in the app where a value :
...
row.myType // resolves to Val1
...
I need to translate row.myType to 1
Simply cast to an int:
int enumValue = (int)row.MyTime;
cast it to int
(int)row.myTime
You can simply cast it to an integer:
(int)row.myType;
myType someEnumVal = myType.Val1;
int intValOfEnum = (int)someEnumVal;

Resources