Database creation

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • Beningram
    Forum Member
    • Sep 2005
    • 18

    Database creation

    Is it possible to create a database from an input field?

    The following would be that if there is a company name then create a database with that company name. if not then create a database with the name.

    Code:
    sConame = Input.GetText("Coname_Inp");
    sName = Input.GetText("Name_Inp");
    
    
    if sConame then
    	db = SQLite.Open(Shell.GetFolder(SHF_MYDOCUMENTS).."\\[I]sConame[/I]");
            else
            db = SQLite.Open(Shell.GetFolder(SHF_MYDOCUMENTS).."\\[I]sName[/I]");
    end
    Is this possible?
  • rexzooly
    No longer a forum member
    • Jul 2007
    • 1512

    #2
    Originally posted by Beningram View Post
    Is it possible to create a database from an input field?

    The following would be that if there is a company name then create a database with that company name. if not then create a database with the name.

    Code:
    sConame = Input.GetText("Coname_Inp");
    sName = Input.GetText("Name_Inp");
    
    
    if sConame then
    	db = SQLite.Open(Shell.GetFolder(SHF_MYDOCUMENTS).."\\[I]sConame[/I]");
            else
            db = SQLite.Open(Shell.GetFolder(SHF_MYDOCUMENTS).."\\[I]sName[/I]");
    end
    Is this possible?
    i don't see why not i don't know too much about the SQLite i am going to start looking in to it later but seems eassy anoth but best thing is just make your self a little demo.

    Comment

    • Beningram
      Forum Member
      • Sep 2005
      • 18

      #3
      Originally posted by Beningram View Post
      Is it possible to create a database from an input field?

      The following would be that if there is a company name then create a database with that company name. if not then create a database with the name.

      Code:
      sConame = Input.GetText("Coname_Inp");
      sName = Input.GetText("Name_Inp");
      
      
      if sConame then
      	db = SQLite.Open(Shell.GetFolder(SHF_MYDOCUMENTS).."\\[I]sConame[/I]");
              else
              db = SQLite.Open(Shell.GetFolder(SHF_MYDOCUMENTS).."\\[I]sName[/I]");
      end
      Is this possible?
      What code needs to be inserted to change the string pulled from the input box so that it can be used as the databse name?

      Comment

      • rexzooly
        No longer a forum member
        • Jul 2007
        • 1512

        #4
        Originally posted by Beningram View Post
        What code needs to be inserted to change the string pulled from the input box so that it can be used as the databse name?
        just like you have there
        Code:
        Cname = InputBox.GetText("Input1");
        Rname = InputBox.GetText("Input2");
        
        if Cname ~= "" then
        	db = SQLite.Open(Shell.GetFolder(SHF_MYDOCUMENTS).."\\sConame");
                else
                db = SQLite.Open(Shell.GetFolder(SHF_MYDOCUMENTS).."\\sName");
        end
        Something like that not tested tho.

        Comment

        • Beningram
          Forum Member
          • Sep 2005
          • 18

          #5
          Originally posted by rexzooly View Post
          just like you have there

          I do not what the database to be called sConame (that is what is currently creates). I want the database to be called whatever is typed in the input box ... ie if "Ford" is typed in the "company" input box I want to create a database called "ford.db"

          Comment

          • rexzooly
            No longer a forum member
            • Jul 2007
            • 1512

            #6
            Originally posted by Beningram View Post
            I do not what the database to be called sConame (that is what is currently creates). I want the database to be called whatever is typed in the input box ... ie if "Ford" is typed in the "company" input box I want to create a database called "ford.db"

            far as i know if its not that its makes it.

            I am just starting to use SQLite my self to change one of my projets from what i read that opens it.



            Help File

            Code:
            -- open the debug window
            Debug.ShowWindow(true);
            
            -- create a database in memory
            dbname = ":memory:";
            db = SQLite.Open(dbname);
            err = Application.GetLastError();
            if err == SQLite.OK then
            
                Debug.Print("Opening database: \"" .. dbname .. "\"\r\n\r\n");
            
                -- create a table and fill it with data
                SQLite.Query(db,"create table Users(userid integer primary key, LastName text, FirstName text, Age integer)");
                SQLite.Query(db,"insert into Users values(1,'Sellers','Ted',48)");
                SQLite.Query(db,"insert into Users values(2,'Blow','Joe',64)");
                SQLite.Query(db,"insert into Users values(NULL,'Dandy','Jim',31)");
                SQLite.Query(db,"insert into Users values(NULL,'Osborne','Super Dave',47)");
                SQLite.Query(db,"insert into Users values(NULL,'Hakimoto','Fuji',52)");
            
                --[[ note: to keep this example from getting too complicated, we'll assume that
                           the table can be created and filled with no errors. In practice,
                           you should check for errors after each call to SQLite.Query. ]]
                
                -- perform a query and store all of the results in a table called tbUsers
                tbUsers = SQLite.QueryToTable(db,"SELECT * FROM Users");
                err = Application.GetLastError();
                if err ~= SQLite.OK then
                    Debug.Print( "Error: " .. SQLite.GetErrorString(err) );
                end
            
                -- display the contents of the table
                
                Debug.Print("Results returned from QueryToTable:\r\n\r\n");
                
                Debug.Print(tbUsers.Columns .." Columns\r\n");
                Debug.Print(tbUsers.Rows    .." Rows\r\n\r\n");
            
                for n = 1,tbUsers.Columns do
                	Debug.Print("Name of column "..n.." is: "..tbUsers.ColumnNames[n].."\r\n");		
                end
                
                Debug.Print("\r\n\r\n");
                
                for nRow = 1,tbUsers.Rows do
                    Debug.Print("Row "..nRow..":\r\n\r\n");
                    Debug.Print("   User ID: "..tbUsers.Data[nRow]["userid"].."\r\n");
                    Debug.Print("   First name: "..tbUsers.Data[nRow]["FirstName"].."\r\n");
                    Debug.Print("   Last name: "..tbUsers.Data[nRow]["LastName"].."\r\n");
                    Debug.Print("   Age: "..tbUsers.Data[nRow]["Age"].."\r\n\r\n");
                end
            
                for nRow = 1,tbUsers.Rows do
                    Debug.Print("Row "..nRow..": ");
                	for nCol = 1, tbUsers.Columns do
                		strColumnName = tbUsers.ColumnNames[nCol];
                		Debug.Print(strColumnName .."="..tbUsers.Data[nRow][strColumnName]);
                		if nCol ~= tbUsers.Columns then
                			Debug.Print(", ");
                		end
                	end
                	Debug.Print("\r\n");
                end
                
                -- close the database
                Debug.Print("\r\nClosing database: \"" .. dbname .. "\"\r\n\r\n");
                SQLite.Close(db)
            
            else
                -- error trying to open the database
                Debug.Print( "Error: " .. SQLite.GetErrorString(err) );
            end

            Comment

            • ShadowUK
              No longer a forum member
              • Oct 2007
              • 1321

              #7
              Code:
              Cname = InputBox.GetText("Input1");
              Rname = InputBox.GetText("Input2");
              
              if Cname ~= "" then
              	db = SQLite.Open(Shell.GetFolder(SHF_MYDOCUMENTS).."\\"..sConame);
                      else
                      db = SQLite.Open(Shell.GetFolder(SHF_MYDOCUMENTS).."\\"..sName);
              end

              Comment

              • rexzooly
                No longer a forum member
                • Jul 2007
                • 1512

                #8
                Originally posted by ShadowUK View Post
                Code:
                Cname = InputBox.GetText("Input1");
                Rname = InputBox.GetText("Input2");
                
                if Cname ~= "" then
                	db = SQLite.Open(Shell.GetFolder(SHF_MYDOCUMENTS).."\\"..sConame);
                        else
                        db = SQLite.Open(Shell.GetFolder(SHF_MYDOCUMENTS).."\\"..sName);
                end
                Hey i was right for a first shot i just started to workin with this like 20 mins ago myself as a way to fix a bug you asked me to fix

                Yay me happy lol

                Comment

                • Beningram
                  Forum Member
                  • Sep 2005
                  • 18

                  #9
                  Originally posted by ShadowUK View Post
                  Code:
                  Cname = InputBox.GetText("Input1");
                  Rname = InputBox.GetText("Input2");
                  
                  if Cname ~= "" then
                  	db = SQLite.Open(Shell.GetFolder(SHF_MYDOCUMENTS).."\\"..sConame);
                          else
                          db = SQLite.Open(Shell.GetFolder(SHF_MYDOCUMENTS).."\\"..sName);
                  end
                  WOOHOO! Thanks ... I was close but the horseshoes and hand grenades weren't cutting it



                  Originally posted by rexzooly View Post
                  Hey i was right for a first shot i just started to workin with this like 20 mins ago myself as a way to fix a bug you asked me to fix

                  Yay me happy lol
                  Thanks to you too Rex. I am SLOWLY figuring this stuff out :yes

                  Comment

                  • rexzooly
                    No longer a forum member
                    • Jul 2007
                    • 1512

                    #10
                    Originally posted by Beningram View Post
                    WOOHOO! Thanks ... I was close but the horseshoes and hand grenades weren't cutting it





                    Thanks to you too Rex. I am SLOWLY figuring this stuff out :yes
                    That is my code i did for you in the first place lol

                    But hey ya i got a thanks so me happy

                    Comment

                    • RizlaUK
                      Indigo Rose Customer
                      • May 2006
                      • 5478

                      #11
                      lol, rex, you had better go to specksavers mate...

                      spot the differance

                      rex's code
                      Code:
                      Cname = InputBox.GetText("Input1");
                      Rname = InputBox.GetText("Input2");
                      
                      if Cname ~= "" then
                      	db = SQLite.Open(Shell.GetFolder(SHF_MYDOCUMENTS).."\\sConame");
                              else
                              db = SQLite.Open(Shell.GetFolder(SHF_MYDOCUMENTS).."\\sName");
                      end

                      shodow's code
                      Code:
                      Cname = InputBox.GetText("Input1");
                      Rname = InputBox.GetText("Input2");
                      
                      if Cname ~= "" then
                      	db = SQLite.Open(Shell.GetFolder(SHF_MYDOCUMENTS).."\\[COLOR="Red"]"..[/COLOR]sConame);
                              else
                              db = SQLite.Open(Shell.GetFolder(SHF_MYDOCUMENTS).."\\[COLOR="Red"]"..[/COLOR]sName);
                      end
                      rex, you was close but you wraped the variables in double quotes
                      Embrace change in your life, you never know, it could all work out for the best

                      Comment

                      • rexzooly
                        No longer a forum member
                        • Jul 2007
                        • 1512

                        #12
                        Indeed i will lol yes i cheated and copyed the db = SQLite.Open(Shell.GetFolder(SHF_MYDOCUMENTS).."\\s Coname");

                        from the first post

                        I am not bothers shodow is kool so are you so HEY lets dance lol sorry crazy moment there

                        Comment

                        • RizlaUK
                          Indigo Rose Customer
                          • May 2006
                          • 5478

                          #13
                          lol, i often have a "specksaver" moment, to many hours staring at code
                          Embrace change in your life, you never know, it could all work out for the best

                          Comment

                          • rexzooly
                            No longer a forum member
                            • Jul 2007
                            • 1512

                            #14
                            Originally posted by RizlaUK View Post
                            lol, i often have a "specksaver" moment, to many hours staring at code
                            nar i am just blond lol ,

                            tired lol

                            Comment

                            Working...
                            X