Giter Club home page Giter Club logo

Comments (12)

JoeyZhu1994 avatar JoeyZhu1994 commented on May 26, 2024 1

Hi,
Your code didn't work on my machine, I've try C++14/C++17/C++ Lastest in my Visual Studio, are you running it on linux? I use Windows 10, and the error reported is the same as mine.
BTW, my sqlite.c/sqlite.h is the latest release Version 3.22.0, does it matter?

from sqlite_orm.

fnc12 avatar fnc12 commented on May 26, 2024

is it a precise your code or some kind of pseudocode? storage2.update() won't compile cause you do not provide an object as an argument to storage2.update(). Also there is semicolon missing at the end of the line. Please check out an update example for more info. Also if there are any compile errors please copy & paste them in the issue - it will help to resolve it quicker. Thanks

from sqlite_orm.

JoeyZhu1994 avatar JoeyZhu1994 commented on May 26, 2024

Thanks for your kindly reply:

It's just pseudocode, I'm sorroy for that.
This is detail one:
void CSqlite_Access::Initialize()
{
// 1. 建立映射,这里可以同时建立多个表与storage的映射关系,make_storage是可变参的
auto table_employee = make_table(Employee::Table_Employee,
make_column(Employee::Column_ID, &Employee::Table::id, primary_key()),
make_column(Employee::Column_Name, &Employee::Table::name),
make_column(Employee::Column_Age, &Employee::Table::age),
make_column(Employee::Column_Address, &Employee::Table::address),
make_column(Employee::Column_Salary, &Employee::Table::salary));

auto storage_employee = make_storage(m_File_Name, table_employee);

// 2. 将表中的数据同步
storage_employee.sync_schema();

storage_employee.begin_transaction();

// 3. 校验表中数据的合法性,使用C++11 Style的迭代方式
// 如果表中某行数据不合法,则将其id保存下来
for (auto &it : storage_employee.iterate<Employee::Table>())
{
	if (!it.IsValid())
	{
		it.Reset();
		storage_employee.update(it);
	}
}


storage_employee.commit(); //  or storage.rollback();

auto table_student = make_table(Student::Table_Student,
	make_column(Student::Column_ID, &Student::Table::id, primary_key()),
	make_column(Student::Column_Name, &Student::Table::name),
	make_column(Student::Column_Age, &Student::Table::age),
	make_column(Student::Column_School, &Student::Table::school));

auto storage_student = make_storage(m_File_Name, table_student);

// 2. 将表中的数据同步
storage_student.sync_schema();

storage_student.begin_transaction();
// 3. 校验表中数据的合法性,使用C++11 Style的迭代方式
// 如果表中某行数据不合法,则将其id保存下来
for (auto &it : storage_student.iterate<Student::Table>())
{
	if (!it.IsValid())
	{
		it.Reset();
		storage_student.update(it);
	}
}
storage_student.commit();

}

If there only exist one update function, compile is OK, If two, the compiler report : "setColumnNames: 未声明的标识符 (means that setColumnNames is not declared)"

from sqlite_orm.

fnc12 avatar fnc12 commented on May 26, 2024

which line has error?

from sqlite_orm.

JoeyZhu1994 avatar JoeyZhu1994 commented on May 26, 2024

line 4930

from sqlite_orm.

fnc12 avatar fnc12 commented on May 26, 2024

Please give me your code for Employee::Table and Student::Table - I'll try to reproduce this bug on my machine

from sqlite_orm.

JoeyZhu1994 avatar JoeyZhu1994 commented on May 26, 2024
#pragma once

#include <string>
#include <memory>

using std::shared_ptr;
using std::string;

namespace DataStorage
{
	class TableBase
	{
	public:
		virtual bool IsValid() = 0;
		virtual void Reset() = 0;
	};

	namespace Employee
	{
		const static string Column_ID = "ID";
		const static string Column_Name = "NAME";
		const static string Column_Age = "AGE";
		const static string Column_Address = "ADDRESS";
		const static string Column_Salary = "SALARY";
		const static string Table_Employee = "EMPLOYEE";

		class Table : public TableBase
		{
		public:
			int id;
			string name;
			int age;
			shared_ptr<string> address;
			int salary;

			virtual bool IsValid()
			{
				return id >= 0;
			}

			virtual void Reset()
			{
				name = u8"";
				address->assign(u8"");
				salary = 0;
			}
		};

	}

	namespace Student
	{
		const static string Column_ID = "ID";
		const static string Column_Name = "NAME";
		const static string Column_Age = "AGE";
		const static string Column_School = "SCHOOL";
		const static string Table_Student = "STUDENT";
		class Table : public TableBase
		{
		public:
			int id;
			string name;
			int age;
			shared_ptr<string> school;

			virtual bool IsValid()
			{
				return id >= 0;
			}

			virtual void Reset()
			{
				name = u8"";
				school->assign(u8"");
				age = 0;
			}
		};
	}

}

They all inherit from a abstract class, I'm not sure if it's allowed.

from sqlite_orm.

JoeyZhu1994 avatar JoeyZhu1994 commented on May 26, 2024

I try to change the Employee::Table and Student::Table to pure struct, but it won't work.

from sqlite_orm.

fnc12 avatar fnc12 commented on May 26, 2024

Everything compiles and works well for me. Here is my code:

#include <iostream>
#include <string>
#include <memory>

#include "sqlite_orm.h"

using std::shared_ptr;
using std::string;

namespace DataStorage
{
    class TableBase
    {
    public:
        virtual bool IsValid() = 0;
        virtual void Reset() = 0;
    };
    
    namespace Employee
    {
        const static string Column_ID = "ID";
        const static string Column_Name = "NAME";
        const static string Column_Age = "AGE";
        const static string Column_Address = "ADDRESS";
        const static string Column_Salary = "SALARY";
        const static string Table_Employee = "EMPLOYEE";
        
        class Table : public TableBase
        {
        public:
            int id;
            string name;
            int age;
            shared_ptr<string> address;
            int salary;
            
            virtual bool IsValid()
            {
                return id >= 0;
            }
            
            virtual void Reset()
            {
                name = u8"";
                address->assign(u8"");
                salary = 0;
            }
        };
        
    }
    
    namespace Student
    {
        const static string Column_ID = "ID";
        const static string Column_Name = "NAME";
        const static string Column_Age = "AGE";
        const static string Column_School = "SCHOOL";
        const static string Table_Student = "STUDENT";
        class Table : public TableBase
        {
        public:
            int id;
            string name;
            int age;
            shared_ptr<string> school;
            
            virtual bool IsValid()
            {
                return id >= 0;
            }
            
            virtual void Reset()
            {
                name = u8"";
                school->assign(u8"");
                age = 0;
            }
        };
    }
    
}

int main(int argc, const char * argv[]) {
    using namespace DataStorage;
    using namespace sqlite_orm;
    
    // 1. 建立映射,这里可以同时建立多个表与storage的映射关系,make_storage是可变参的
    auto table_employee = make_table(Employee::Table_Employee,
                                     make_column(Employee::Column_ID, &Employee::Table::id, primary_key()),
                                     make_column(Employee::Column_Name, &Employee::Table::name),
                                     make_column(Employee::Column_Age, &Employee::Table::age),
                                     make_column(Employee::Column_Address, &Employee::Table::address),
                                     make_column(Employee::Column_Salary, &Employee::Table::salary));
    
    auto m_File_Name = "issue84.sqlite";
    auto storage_employee = make_storage(m_File_Name, table_employee);
    
    // 2. 将表中的数据同步
    storage_employee.sync_schema();
    
    storage_employee.begin_transaction();
    
    // 3. 校验表中数据的合法性,使用C++11 Style的迭代方式
    // 如果表中某行数据不合法,则将其id保存下来
    for (auto &it : storage_employee.iterate<Employee::Table>())
    {
        if (!it.IsValid())
        {
            it.Reset();
            storage_employee.update(it);
        }
    }
    
    
    storage_employee.commit(); //  or storage.rollback();
    
    auto table_student = make_table(Student::Table_Student,
                                    make_column(Student::Column_ID, &Student::Table::id, primary_key()),
                                    make_column(Student::Column_Name, &Student::Table::name),
                                    make_column(Student::Column_Age, &Student::Table::age),
                                    make_column(Student::Column_School, &Student::Table::school));
    
    auto storage_student = make_storage(m_File_Name, table_student);
    
    // 2. 将表中的数据同步
    storage_student.sync_schema();
    
    storage_student.begin_transaction();
    // 3. 校验表中数据的合法性,使用C++11 Style的迭代方式
    // 如果表中某行数据不合法,则将其id保存下来
    for (auto &it : storage_student.iterate<Student::Table>())
    {
        if (!it.IsValid())
        {
            it.Reset();
            storage_student.update(it);
        }
    }
    storage_student.commit();
    
    return 0;
}

Did you forget to set -std=c++14?

from sqlite_orm.

fnc12 avatar fnc12 commented on May 26, 2024

I compiled it on macOS with Xcode 9 (clang++). Also CI compiles this code on Ubuntu. Latest SQLite is good. Please show me error log from IDE

from sqlite_orm.

JoeyZhu1994 avatar JoeyZhu1994 commented on May 26, 2024

My visual studio showed as below:
错误 C2065 “setColumnNames”: 未声明的标识符 (setColumnNames is not declared) c:\users\jo3y\source\repos\scopetest\scopetest\sqlite_orm.h 4930
错误 C2228 “.emplace_back”的左边必须有类/结构/联合 (no class/struct/union exists on the left side of .emplace_back ) c:\users\jo3y\source\repos\scopetest\scopetest\sqlite_orm.h 4920

from sqlite_orm.

fnc12 avatar fnc12 commented on May 26, 2024

@JoeyZhu1994 please pull the latest source and try again. Looks like visual studio cannot find variables with implicit lambda capture (and this is horrible). I've changed lambda capture to explicit, now everything must work. If build still fails please reopen the issue and post the error text. Thanks

from sqlite_orm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.